jueves 27 de agosto de 2009
Custom ASP.net Web Application in MOSS
The referenced file '/TEMPLATE/LAYOUTS/MyWebApp/MyMasterPage.master' is not allowed on this page. at System.Web.UI.TemplateParser.ProcessError(String message) at System.Web.UI.BaseTemplateParser.GetReferencedType(VirtualPath virtualPath, Boolean allowNoCompile) at System.Web.UI.PageParser.ProcessMainDirectiveAttribute(String deviceName, String name, String value, IDictionary parseData) at System.Web.UI.TemplateParser.ProcessMainDirective(IDictionary mainDirective)
Para solucionarlo hemos hecho lo siguiente:
- Modificar el atributo MasterPageFile de la directiva Page de nuestra custom .aspx indicandole la página maestra application.master.
MasterPageFile="~/_layouts/application.master"
- Luego en el fichero .cs (Code Behind) hemos asignado nuestra página maestra en el evento PreInit
protected void Page_PreInit(object sender, EventArgs e)
{
this.MasterPageFile = "~/_layouts/MyWebApp/MyMasterPage.master";
}
jueves 28 de mayo de 2009
Permisos EventLog
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Eventlog\MyLogName\CustomSD
Para permitir a los usuarios autenticados permisos de escritura se ha de aññadir el siguiente permiso:
(A;;0x0002;;;AU)
Para permitir a un usuario específico permiso de escritura debermos especificar su SID:
(A;;0x0002;;;SID-OF-USER-ACCOUNT)
martes 21 de abril de 2009
CopyUtil.aspx - Una gran Application Page
Para ir a un item concreto tenemos que construir la siguiente URL:
http://server/_layouts/CopyUtil.aspx?Use=id&Action=dispform&ItemId=X&ListId=X&WebId=X&SiteId=X
sustituyendo las X por los ID's correspondientes. El parámetro "action" puede ser sustituido por dispform o editform, para que nos rediriga a la URL que nos muestra el item o para que nos rediriga a la URL para editar el item.
jueves 12 de febrero de 2009
Error wizard sharepoint
Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException was thrown. Additional exception information: An update conflict has occurred, and you must re-try this action. The object DiagnosticsService Parent=SPFarm Name=SharePoint_Config is being updated by Domain\User, in the w3wp process, on machine SERVER. View the tracing log for more information about the conflict. Microsoft.SharePoint.Administration.SPUpdatedConcurrencyException: An update conflict has occurred, and you must re-try this action. The object DiagnosticsService Parent=SPFarm Name=SharePoint_Config is being updated by Domain\User, in the w3wp process, on machine SERVER. View the tracing log for more information about the conflict.
Al parecer esto sucede cuando hay un objeto bloqueado a nivel de SPFarm. Para solventar este problema hay que limpiar la cache de configuración de Windows SharePoint Services.
http://support.microsoft.com/kb/944267/en-us/
¿Y donde se encuentra esta cache?
Esta caché se encuentra en:
C:\Documents and Settings\All Users\Application Data\Microsoft\SharePoint\Config\[GUID]
La solución pasa por borrar todos los xml de esta carpeta [CUIDADO NO BORRAR EL ARCHIVO cache.ini], luego se ha de editar el archivo cache.ini y poner un 1 y guardar.
http://support.microsoft.com/kb/939308/en-us/
jueves 5 de febrero de 2009
Copiar items y folders entre DocumentLibrary manteniendo sus campos
1. Igualar los campos de las bibliotecas:
public static void IgualarCampos(SPDocumentLibrary origen, SPDocumentLibrary destino)
{
if (origen == null destino == null) throw new ArgumentException("Las bibliotecas destino y origen no pueden ser nulas");
try
{
List
foreach (SPField field in destino.Fields)
{
listaCamposDestino.Add(field);
}
// Compara con origen y crea las necesarias en destino
foreach (SPField field in origen.Fields)
{
SPField campoBuscado = listaCamposDestino.Find(delegate(SPField campo)
{
return campo.Id == field.Id;
});
// Si no existe lo añadimos
if (campoBuscado == null )
{
// Se crea campo en lista destino.
destino.Fields.Add(field);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
2. Funciones recursivas para recorrer todos los folders y crearlos en el destino así como los items por folder:
public static void CopyFoldersAndItems(SPDocumentLibrary origen, SPDocumentLibrary destino)
{
if (origen == null destino == null) throw new ArgumentException("Las bibliotecas destino y origen no pueden ser nulas");
try
{
string urldestinofolders = destino.RootFolder.ServerRelativeUrl.ToString();
SPFolderCollection foldersdestino = destino.ParentWeb.GetFolder(urldestinofolders).SubFolders;
string urlorigenfolders = origen.RootFolder.ServerRelativeUrl.ToString();
SPFolderCollection foldersorigen = origen.ParentWeb.GetFolder(urlorigenfolders).SubFolders;
foreach (SPFile file in origen.RootFolder.Files)
{
SPFile newFile = destino.RootFolder.Files.Add(file.Name, file.OpenBinary(), file.Author, file.ModifiedBy, file.TimeCreated, file.TimeLastModified);
SPListItem newItem = newFile.Item;
foreach (SPField f in file.Item.Fields)
{
if (!f.ReadOnlyField) newItem[f.InternalName] = file.Item[f.InternalName];
}
newItem["Modificado"] = file.TimeLastModified;
newItem["Creado"] = file.TimeCreated;
newItem.UpdateOverwriteVersion();
}
CopyFoldersAndItems(foldersorigen, foldersdestino);
}
catch (Exception ex)
{
throw ex;
}
}
public static void CopyFoldersAndItems(SPFolderCollection origen, SPFolderCollection destino)
{
try
{
foreach (SPFolder folder in origen)
{
if (folder.Name != "Forms")
{
SPFolder nuevo = destino.Add(folder.Name);
foreach (SPFile file in folder.Files)
{
SPFile newFile = nuevo.Files.Add(file.Name, file.OpenBinary(), file.Author, file.ModifiedBy, file.TimeCreated, file.TimeLastModified);
SPListItem newItem = newFile.Item;
foreach (SPField f in file.Item.Fields)
{
if(!f.ReadOnlyField) newItem[f.InternalName] = file.Item[f.InternalName];
}
newItem["Modificado"] = file.TimeLastModified;
newItem["Creado"] = file.TimeCreated;
newItem.UpdateOverwriteVersion();
}
if (folder.SubFolders.Count > 0) CopyFoldersAndItems(folder.SubFolders, nuevo.SubFolders);
}
}
}
catch (Exception ex)
{
throw ex;
}
}
lunes 2 de febrero de 2009
Obtener webparts de una página (MOSS 2007)
Aquí tenemos un ejemplo para obtener las webparts de una página de publicación,
una vez tenemos el tipo de la webpart podemos hacer un casting y acceder a sus propiedades para consultarlas y/o modificarlas.
using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebPartPages;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using(SPSite siteCollection = new SPSite("http://localhost:44236"))
{
using(SPWeb site = siteCollection.OpenWeb())
{
using (SPLimitedWebPartManager manager = site.GetLimitedWebPartManager("Paginas/default.aspx", PersonalizationScope.Shared))
{
foreach (System.Web.UI.WebControls.WebParts.WebPart wp in manager.WebParts)
{
Console.WriteLine(wp.GetType().ToString());
}
}
}
}
Console.ReadLine();
}
}
}
Añadir link abra el panel de control en una webpart
En el primer caso tenemos una función, ToolPane.GetShowExtensibleToolPaneEvent, que pasándole el id de nuestra webpart nos devuelve un string con la llamada javascritpt que queremos realizar, por lo que el código quedaría algo como:
public class WPPrueba : Microsoft.SharePoint.WebPartPages.WebPart
{
#region Variables
private string _propiedad;
#endregion
#region Propieades
[Browsable(true),
Category("Mis Propiedades"),
DefaultValue(""),
WebPartStorage(Storage.Shared),
FriendlyName("Propiedad"),
Description("Propiedad.")]
public string Propiedad
{
get { return _propiedad; }
set { _propiedad = value; }
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
try
{
if (Propiedad == null Propiedad == "")
{
string funcionJavaScript = ToolPane.GetShowExtensibleToolPaneEvent(this.ID);
string html = "abra el panel de herramientas";
writer.Write(html);
}
else
{
writer.Write("hello world");
}
}
catch(Exception ex)
{
}
}
#endregion
}
En el segundo caso no podemos hacer esto por lo que añadiremos el código javascript a mano:
string html = " abra el panel de herramientas";
