Arquivo da Categoría: Desenvolvemento SharePoint

Explicación Simple: “O valor non se enmarca dentro do rango de esperar.”

Actualización: An anonymous poster left a great comment about internal names. Be sure to read it.

Ao traballar con receptores de eventos e outros códigos que referencias SharePoint elementos de lista a través do modelo de obxecto, Eu moitas veces cometen erros que xeran este erro en tempo de execución:

Erro Conchango.xyzzyEventReceiver receptor cargar e executar eventos xyzzy, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = 0dc50a750396c3ac. Additional information is below. : Value does not fall within the expected range.

I think this is a fairly generic error that is potentially caused many different ways. Con todo, one simple explanation is that I’m referencing a field incorrectly. If the name of the field is "Due Date", Debo referencia-como este en un receptor de eventos:

properties.ListItem["Data de caducidade"]

Cando cometer erros ou utilizar o caso mal ao facer referencia ao campo, SharePoint generates the above mentioned runtime error. Por exemplo, iso é malo:

properties.ListItem["Data de caducidade"]

</final>

Rexístrate para o meu blog.

Rápido & Fácil: Crear un cartafol e asigne un tipo de contido (Ou, Ten os seus KPIs e comen máis)

Co fin de evitar un problema KPI Eu escribín sobre aquí, I did some testing and discovered that KPI’s work against folders with meta data in the same way that they work against documents or list items. I proved it out by creating a new content type based on the folder content type and then added a few fields. I created some indicators and proved to myself that KPIs work as expected. This was welcome news. It’s not perfect, because the drill-down you get from the KPI against the folders is not exactly what you want. This isn’t too much a drawback in my case because 1) os usuarios finais non saben de nada e 2) the drill-down goes to a folder. They click the folder name and they are at the item. It’s two clicks instead of one, o que non é o fin do mundo.

This flowed nicely with the work I was doing. I am creating a folder for every document that gets uploaded. This is done via an event receiver. Como resultado, é unha peza de bolo para manter o pai do cartafol meta data in sync with the KPI-driven meta data from the file itself since the plumbing is already in place. This allows me to have my KPI’s and eat them too 🙂

I modified the event receiver to add the folder and then set this new folder’s content type to my custom KPI-friendly content type. This bit of code did the trick:

 SPFolderCollection srcFolders = targetWeb.GetFolder("Documents").SubFolders;
  SPFolder addedFolder = srcFolders.Add(properties.ListItem.ID.ToString());
  SPContentTypeId kpiCT = novo SPContentTypeId("0x0120002A666CAA9176DC4AA8CBAA9DC6B4039F");
  addedFolder.Item["Content Type ID"] = KpiCT;
  addedFolder.Item.Update();

Para atopar o real Content Type ID, Eu acessei este tipo de contidos a través de configuración do sitio web e copiar / pegar lo da URL, como se mostra:

imaxe

</final>

Rexístrate para o meu blog!

Fácil e rápida: Obter o SPFolder dun SPListItem nun receptor de eventos

Eu odio admitir iso, but I struggled with this one all day. My event receiver needs to update a field of its parent folder. This little bit shows how to do it:

privado invalidar UpdateParentFolder(SPItemEventProperties Propiedades)
{

SPFolder thisItemFolder = properties.ListItem.File.ParentFolder;
thisItemFolder.Item["ZZ Approval Status"] = "Good news, todos!";
thisItemFolder.Item.Update();


} // UpdateParentFolder

Neste caso, Estou traballando con unha biblioteca de documentos e as propiedades proveñen dun evento ItemAdded.

O truco é que non se pode obter o SPFolder do elemento directamente do elemento en si (i.e. properties.ListItem.Folder é nulo). Pola, ir ao ficheiro asociado do elemento da lista e obter o cartafol do ficheiro.

</final>

Rexístrate para o meu blog!

Yet Another evento Truco Debug Receiver

I’m sure I’m not the first person to come up with this. Con todo, I haven’t noticed anyone publish a trick like this since I started paying close attention to the community last July. Así, Eu penso que eu ía publicar esta información de depuración rápido e sinxelo.

Estou traballando nun receptor de eventos que comezou a xerar ese erro 12 colmea:

Erro Conchango.xyzzyEventReceiver receptor cargar e executar eventos xyzzy, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = blahbalhbalh. Additional information is below. : Referencia de obxecto non está definida para unha instancia dun obxecto.

I didn’t know where I had introduced this bug because I had done too many things in one of my code/deploy/test cycles.

Tente esta solución para obter o meu PDB alí coa esperanza de que o SharePoint 12 colmea ía amosar o seguimento de pila, but no luck. I don’t know if it’s possible and if someone does, por favor me aviso 🙂

Sei que é posible escribir as súas propias mensaxes de rexistro ao 12 colmea. Frankly, Eu quería algo un pouco menos asustado e máis rápido para aplicar.

Houbo-me que eu podería polo menos ter unha información básica de seguimento, captura e re-lanzar excepcións xenéricas como esta:

  intentar {
    UpdateEditionDate(Propiedades);
  }
  incorporarse (Excepción e)
  {
    xogar novo Excepción("Dispatcher, UpdateEditionDate(): Excepción: [" + e.ToString() + "].");
  }

Este mostrou-se no 12 colmea deste xeito:

Erro Conchango.xyzzyEventReceiver receptor cargar e executar eventos xyzzy, Version = 1.0.0.0, Culture = neutral, PublicKeyToken = blahblahblah. Additional information is below. : Expedidor, UpdateEditionDate(): Excepción: [System.NullReferenceException: Referencia de obxecto non está definida para unha instancia dun obxecto. at Conchango.xyzzyManagementEventReceiver.UpdateEditionDate(Propiedades SPItemEventProperties) at Conchango.xyzzyManagementEventReceiver.Dispatcher(Propiedades SPItemEventProperties, EventDescription cadea)].

Iso me deu todos os detalles que eu precisaba para rastrexar este problema específico e esperamos usalo moito de aquí para diante.

</final>

Rexístrate para o meu blog!

Solución: SPQuery non busca Folders

This past week I was implementing an "evolving" solution for a client that uses BDC and SPQuery and ran into some difficulty using SPQuery against a document library containing folders. Bottom line: assign "recursive" ao atributo de vista da consulta.

O meu escenario:

  • O luns, Eu enviar un documento e ofrecer algúns datos de meta.
  • A semana seguinte,, I upload a new document. Much of this new document’s meta data is based on the document I uploaded on Monday (which we call the "master document").
  • Creamos unha fachada de servizo web que ofrece unha interface BDC-friendly para a lista para que os usuarios poidan facilmente atopar ese documento luns a través dunha investigación de título.
  • A BDC data column provides a friendly user interface. (Iso forma parte da miña tentativa de usar BDC para unha columna de investigación máis agradable).

A final BDC servizo fachada utiliza unha consulta como esta a facer o lookup:

 // Usado U2U ferramenta para auxiliar na xeración de esta consulta CAML.
      oQuery.Query =
        "<Onde>";

      se (titleFilter.Length > 0)
        oQuery.Query  =
          "  <E>";

      oQuery.Query  =
        "    <E>" +
        "      <Geq>" +
        "        <FieldRef Name=\"DocumentId\" />" +
        "        <Value Type=\"Text\">" + MiniD + "</Valor>" +
        "      </Geq>" +
        "      <Leq>" +
        "        <FieldRef Name=\"DocumentId\" />" +
        "        <Value Type=\"Text\">" + maxId + "</Valor>" +
        "      </Leq>" +
        "    </E>";

      se (titleFilter.Length > 0)
        oQuery.Query  =
          "    <Contén>" +
          "      <FieldRef Name=\"Title\" />" +
          "      <Value Type=\"Text\">" + titleFilter + "</Valor>" +
          "    </Contén>" +
          "  </E>";
      oQuery.Query  =
        "</Onde>";

Durante a fase inicial de desenvolvemento, this worked great. Con todo, nós introducimos cartafoles no directorio para resolver algúns problemas e, de súpeto, my BDC picker wouldn’t return any results. I tracked this down to the fact that the SPQuery would never return any results. We used folders primarily to allow multiple files with the same name to be uploaded but with different meta data. When the file is uploaded, creamos un cartafol con base na identificación do elemento da lista e move o ficheiro alí (Eu escribín sobre iso aquí; tivemos resultados mixtos con esta visión, pero en xeral, el funciona ben). The user don’t care about folders and in fact, don’t really understand that there are any folders. We have configured all the views on the library to show items without regard to folders.

I hit this problem twice as the technical implementation evolved and solved it differently each time. The first time, I wasn’t using the CONTAINS operator in the query. Without a CONTAINS operator, I was able to solve the problem by specifying the view on the SPQuery’s contructor. Instead of using the default constructor:

SPList oList = web.Lists["Documents"];

SPQuery oQuery = novo SPQuery();

Eu en vez utilizar un constructor que especificou unha vista:

SPList oList = web.Lists["Documents"];

SPQuery oQuery = novo SPQuery(oList.Views["All Documents"]);

Isto resolveu o problema e comece a poñer os meus resultados.

I then added the CONTAINS operator into the mix and it broke again. It turns out that the CONTAINS operator, tan lonxe como podo dicir, non funciona co punto de vista do mesmo xeito que a un simple geq / LEQ operators. I did some searching and learned that the query’s ViewAttributes should be set to "Recursive", como no:

oQuery.ViewAttributes = "Scope=\"Recursive\"";

That solved the problem for CONTAINS. En realidade, Isto tamén resolveu o meu problema de investigación orixinal e se eu tivese especificar o atributo recursivo por primeira vez, Eu non tería corrido para a cuestión de novo.

O feito de que un SPQuery visión baseada funciona para algúns operadores (GEQ/LEQ) e non outros (Contén), xunto co feito de que KPIs non parecen traballar en conxunto con bibliotecas de documentos cartafol contén me leva a pensar que SPQuery ten algúns problemas de ortogonalidade.

Agradecementos especiais:

  • O persoal da U2U ea súa ferramenta de consulta.
  • Michael Hoffer de gran "learning by doing" blog, comentarios e respostas.

</final>

Rexístrate para o meu blog!

Moss KPI erro? Indicador lista Amarre a biblioteca de documentos con pastas

Actualización 02/29/08: I solved this problem by creating a folder and then assigning a content type to the folder which has the meta data I need for the KPIs. Eu describe que un pouco máis de detalles aquí.

We have implemented a technical solution where users upload documents to a document library. An event receiver creates a directory and moves the file to that directory (usando unha técnica similar ao que escribín sobre aquí). We’ve successfully navigated around the potential issues caused by event receivers that rename uploaded files (mainly because users never start their document by clicking on "New" mais en vez diso crear os documentos localmente e despois envialos).

The meta data for these documents includes a Yes/No site column called "Urgent" and another site column called "Status". We need to meet a business requirement that shows the percentage of "Urgent" documents whose status is "Pending".

Xeralmente isto é simple e eu describe algo moi parecido a isto no Beagle SharePoint con moitas capturas de pantalla se vostede está interesado.

En poucas palabras, Eu fixen o seguinte:

  • Create a view on the doc library called "Pending".
  • Configure o punto de vista de ignorar estructura de cartafoles.
  • Crear unha lista de KPI.
  • Create an indicator in the list that points to the doc lib and that "Pending" ver.

This simply does not work. The KPI shows my target (e.g. cinco documentos urxentes) but always shows the actual number of urgent documents as zero. Paradoxically, afondar nos detalles, it shows the five urgent documents in the list. I created a very simple scenario with two documents, one in a folder and one not. Here is the screen shot:

imaxe

The above screen shot clearly shows there are two documents in the view but the "value" is one. The "CamlSchema" with blank document Id is in the root folder and the other is in a folder named "84".

Paréceme que aínda que especifique unha visión, the KPI doesn’t honor the "show all items without folders" fixación e, no canto, Limítase a cartafol raíz.

Se eu está mal, por favor mande-me unha liña ou deixar un comentario.

</final>

Rexístrate para o meu blog!

Technorati Tags:

Solución para o problema: “FileNotFoundException” Co meu recurso Receiver.

I was working on a feature last week that would add some event receivers to a specific list instance. (Eu escribín un pouco sobre esta lista receptor aquí).

Usar a liña de comandos, Podería instalar o recurso sen erro (pero mira abaixo o erro oculto). When I tried to deploy the feature on the site, MOSS complained of a "FileNotFoundException" error. This blog entry describes how I solved it.

Este é o erro que Moss me mostrou o navegador web:

Feature ‘b2cb42e3-4f0a-4380-aaba-1ef9cd526f20’ could not be installed because the loading of event receiver assembly "xyzzyFeatureReceiver_0" fracasado: System.IO.FileNotFoundException: Could not load file or assembly ‘xyzzyFeatureReceiver_0’ ou unha das súas dependencias. O sistema non pode atopar o ficheiro especificado.
O nome do ficheiro: ‘xyzzyFeatureReceiver_0’
at System.Reflection.Assembly.nLoad(AssemblyName filename, Codebase cadea, AssemblySecurity evidencia, Asemblea locationHint, StackCrawlMark& apilar solo, Booleana throwOnFileNotFound, ForIntrospection Boolean)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, AssemblySecurity evidencia, StackCrawlMark& apilar solo, ForIntrospection Boolean)
at System.Reflection.Assembly.InternalLoad(Cordas assemblyString, AssemblySecurity evidencia, StackCrawlMark& apilar solo, ForIntrospection Boolean)
at System.Reflection.Assembly.Load(Cordas assemblyString)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()
WRN: Rexistro de conexións de assembly está desactivado.
Para activar o rexistro de erros de assembly, definir o valor de rexistro [HKLM Software Microsoft Fusion!EnableLog] (DWORD) para 1.
Nota: Hai algunha perda de rendemento asociada ao rexistro de fallo de conexión de assembly.
Para desactivar este recurso, elimine o valor do Rexistro [HKLM Software Microsoft Fusion!EnableLog].

Solucionar problemas con Windows SharePoint Services.

Sei como facer que deliberadamente este erro: don’t install the assembly in the GAC. Pero, it was in the GAC. I normally install assemblies into the GAC by dragging them into the c:\windows\assembly folder using windows explorer. I’ve never felt 100% cómodo facendo iso, porque eu sempre pensei que Gacutil existiu por unha razón … so I tried that. It made no difference.

Eu procurei as Internets e atopei este post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2243677&SiteID=1

O cartel pasou a ser co mesmo bit raíz do código (do libro WSS Dentro desta lista) so that was a hopeful sign. Con todo, a suxestión de decorar a montaxe cunha [montaxe: ] directive didn’t make sense to me. I tried it anyway and I was right. It made no difference.

Then I noticed that my class definition was not public. I made it public and that made no difference.

Seguinte, I went to the trouble of enabling the "assembly bind failure log" (seguindo as instrucións útiles e precisas proporcionadas) and this is where things started to get interesting. That log shows me that the runtime is searching everywhere on that server for my assembly. It even appears to be searching for it in my medicine cabinet. Pero … non vai buscalo no GAC.

I put on my winter jacket and go searching the Internets again and find that someone has had this problem too. The lengthy discussion in that posting peters off into nothing and I can’t find a solution.

I move my assembly into one of the places the log claims it’s searching and I make a little more progress. I’m rewarded with a new error in the browser when I try to activate the feature:

Failed to create feature receiver object from assembly "xyzzyFeatureReceiver_0", type "Conchango.xyzzyFeatureReceiver" ao recurso de b2cb42e3-4f0a-4380-aaba-1ef9cd526f20: System.ArgumentNullException: O valor non pode ser nulo.
O nome do parámetro: tipo
at System.Activator.CreateInstance(Tipo Tipo, Booleana nonPublic)
at System.Activator.CreateInstance(Tipo Tipo)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

Solucionar problemas con Windows SharePoint Services.

Tempo para unha última viaxe para as Internets!

Esta vez descubro, previsiblemente, that MOSS issues this error because the assembly is not in GAC.

Quero aproveitar algo positivo deste e tentar sentir algo orgulloso de que eu creei o Fugitivo de conxuntos MSIL, but it’s not working. I’m just plain annoyed. I find myself muttering "chicken or the egg" baixo a miña respiración.

I finally decide to punt. I create an entirely new project and copy/paste the code from the incredible-cloaked-from-the-GAC-assembly non-working project over to this new project. (I look for a build flag called something like "hide from assembly binding if installed in the GAC" pero non pode atopar un).

Eu instalar recurso e activa-lo e … funciona! Así, despois de todo isto, I had to basically ‘reboot’ my project. Esta é outra razón pola que eu odio ordenadores.

I did learn something useful from this. I had been installing features using the stsadm command line all day long and been using the "-force" option out of habit. Por algunha razón, I did not use the -force option when I installed the new project. Este tempo, Eu fixen realmente, truly forget to copy this new project’s assembly into the GAC. Como resultado, I received that "FielNotFoundException" error. Este tempo, I got it from stsadm, not when I tried to activate the feature via the web browser. Así, -force actually plays two roles. It allows you to re-install an existing feature. It also allows you to install a buggy feature that cannot work at runtime by suppressing the error. It probably says as much in the help somewhere but I never noticed it.

</final>

Rápido & Fácil: Renomear o ficheiro cargado empregando SharePoint obxecto Model a través dun receptor de eventos

Actualización: This works but there are significant limitations which are described in the comments. This may still be useful in some cirumstances.

Actualización 2: O meu proxecto actual, users always upload documents. Como resultado, I don’t run into a problem where MS Word is running and thinks that the file was renamed on it. I did run into a problem, "the file was modified by someone else" and solved this via a simple semaphore type flag. Users need to change a meta data field from its default value to something else. The itemupdated() receptor busca por un valor válido alí antes de realmente facer a renomeação e desde entón, I have not had any problems. Your mileage may vary.

I have a client requirement to change the name of files uploaded to a specific document library to conform with a particular naming convention. The API does not provide a "rename()" método. Pola, usan "MoveTo(…)". Here is a minimal bit of code to accomplish this:

 público substituír invalidar ItemAdded(SPItemEventProperties Propiedades)
        {
            SPFile f = properties.ListItem.File;

            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url + "/xyzzy.doc");
            f.Update();

        }

The only tricky bit is the "properties.ListItem.ParentList.RootFolder.Url". The MoveTo() method requires a URL. That mashed up string points me to the root folder of my current document library. This allows me to avoid any hard coding in my event receiver.

Esta é unha versión máis útil que fai o mesmo, but assigns the name of the file to "Title":

 público substituír invalidar ItemAdded(SPItemEventProperties Propiedades)
        {
            DisableEventFiring();

            // Asignar o título deste artigo para o nome do ficheiro en si.
 // NOTA: Esta asignación debe ocorrer antes de modificar o propio arquivo.
 // Chamando actualización() no SPFile parece invalidar as propiedades en
 // nalgún sentido.  Updates to "Title" puido ata que o cambio (e actualización() chamar)
 // foron movidos fronte á mudanza do nome do ficheiro.
            properties.ListItem["Title"] = Properties.ListItem.File.Name;

            properties.ListItem.Update();

            SPFile f = properties.ListItem.File;

            // Obter a extensión do ficheiro.  Necesitamos que máis tarde.
 corda spfileExt = novo FileInfo(f.Name).Extensión;

            // Renomeie o ficheiro para a identificación do elemento da lista e utilizar a extensión do ficheiro para manter
 // que parte dela intacta.
            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
                "/" + properties.ListItem["ID"] + spfileExt);

            // Comprometer o movemento.
            f.Update();

            EnableEventFiring();
        }

Consello Rápida: Content Query web Part, Busca de valor de columna e XSL

I have a column name in a content type named "Real Estate Location".

That column is of type "lookup".

Eu modifiquei <CommonViewFields> e ItemStyle.xsl para mostrar a columna.

Un simple <XSL:valor de select =…> retorna un valor interno que inclúe datos de posición ordinal, como:

1;#Miami

Para obter o valor humano-friendly, usar XSL substring-after, como se mostra:

<XSL:value-of select="substring-after(@ Real_x005F_x0020_Estate_x005F_x0020_Location,'#')"></XSL:valor de>

Use esta técnica cando se está a traballar con valores de investigación en transformacións XSL e que obter o valor humano-friendly.

</ Comezo>

Technorati Tags: , ,

Fácil e rápida: Determinar Nome da Columna Interna de unha columna de páxina

Actualización: Jeremy Thake ten un blog sobre iso e poñer-se algúns código para unha aplicación de consola que mostra os nomes internos.

I was trying to get a content query web part to display a due date from a task and because the screen label is "Due Date", I asumido que o nome da columna para usar en <CommonViewFields> is "Due_x0020_Date".

Mal!

The real column name in this case was "DueDate".

Como é que eu atopalo? I re-read Heather Blog de Salomón sobre a modificación CQWP to show additional columns of data. She describes this process at step #13. Trust it. It’s correct. Polo menos, it was correct for me. I did not trust it at first for another column with a much longer name.

I say "Trust it" because I did not trust it and probably wasted near two hours butting my head up against a wall. After I resolved the "DueDate" nome, Quería engadir outro campo de <CommonViewFields>. Using the Solomon technique, I was getting a column name like "XYZ_x0020_Project_x0020_Due_x00".

Eu penso para min mesmo, that’s clearly a truncated name. I went ahead and un-truncated it with no success. I finally used the seemingly truncated name and it worked.

Consello extra: Cando estaba a traballar co CQWP, se eu engade un nome interno malo <CommonViewFields>, the CQWP would tell me that the query had returned no results. Pero, se eu engade un tipo de datos para o nome do campo, it would return a result. Adding the data type actually masked a problem since I was referencing a non-existent field. I could add it, pero cando intento amosar o seu valor, I would always get a blank.

Isto non mascarou o erro:

<CommonViewFields>Due_x0020_Date;</CommonViewFields>

Este fixo enmascarar o erro:

<CommonViewFields>Due_x0020_Date,Datetime;</CommonViewFields>

</final>