kategorie Argief: SharePoint Ontwikkeling

Eenvoudige verduideliking: “Waarde nie binne die verwagte reeks.”

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

Wanneer jy werk met geleentheid ontvangers en ander kode wat verwysings SharePoint lys items deur middel van die voorwerp model, Ek maak dikwels foute wat hierdie fout tydens looptyd:

Fout met laai en hardloop gebeurtenis ontvanger Conchango.xyzzyEventReceiver in Xyzzy, Weergawe = 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. Egter, one simple explanation is that I’m referencing a field incorrectly. If the name of the field is "Due Date", Ek moet dit verwys soos dit in 'n geval van 'n ontvanger:

properties.ListItem["Vervaldatum"]

Toe ek spelfoute maak of die verkeerde geval wanneer die verwysing na die veld, SharePoint generates the above mentioned runtime error. Byvoorbeeld, Dit is verkeerd:

properties.ListItem["Vervaldatum"]

</einde>

Skryf in op my blog.

Technorati Tags:

Vinnige & Maklik: Skep 'n gids en Ken 'n tipe inhoud (Of, Jou KPI's en hulle eet ook)

Ten einde te werk om 'n KPI probleem Ek het oor hier, 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) die einde gebruikers nie 'n beter en weet 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, dit is nie die einde van die wêreld.

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. As 'n gevolg, dit is 'n stukkie van die koek te hou van die ouer gids 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("Dokumente").Subgidse;
  SPFolder addedFolder = srcFolders.Add(properties.ListItem.ID.ToString());
  SPContentTypeId kpiCT = nuwe SPContentTypeId("0x0120002A666CAA9176DC4AA8CBAA9DC6B4039F");
  addedFolder.Item["Content Type ID"] = KpiCT;
  addedFolder.Item.Update();

Die werklike inhoud Type ID op te spoor, Ek verkry dat die inhoud tipe via site instellings en afskrif / geplak van die URL soos getoon:

beeld

</einde>

Skryf in op my blog!

Technorati Tags: ,

Vinnige en maklike: Kry van die SPFolder 'n SPListItem in 'n gebeurtenis ontvanger

Ek haat dit om te erken, 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:

private nietig UpdateParentFolder(SPItemEventProperties eienskappe)
{

SPFolder thisItemFolder = properties.ListItem.File.ParentFolder;
thisItemFolder.Item["ZZ Goedkeuring Status"] = "Goeie nuus, almal!";
thisItemFolder.Item.Update();


} // UpdateParentFolder

In hierdie geval, Ek werk met 'n dokument biblioteek en die eienskappe kom uit 'n ItemAdded gebeurtenis.

Die geheim is dat jy nie kan kry die SPFolder van die item direk van die item self (d.w.z. properties.ListItem.Folder, is van nul). In plaas daarvan, gaan na die lys-item se geassosieer File en kry die lêer gids.

</einde>

Skryf in op my blog!

Technorati Tags:

Nog 'n gebeurtenis Ontvanger Debug Trick

I’m sure I’m not the first person to come up with this. Egter, I haven’t noticed anyone publish a trick like this since I started paying close attention to the community last July. So, Ek het gedink dat ek dit hierdie vinnige en maklike debug punt wil pos.

Ek werk op 'n gebeurtenis ontvanger wat hierdie fout in die begin te genereer 12 Hive:

Fout met laai en hardloop gebeurtenis ontvanger Conchango.xyzzyEventReceiver in Xyzzy, Weergawe = 1.0.0.0, Culture = neutral, PublicKeyToken = blahbalhbalh. Additional information is below. : Object verwys nie na 'n geval van 'n voorwerp.

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.

Ek het probeer om hierdie oplossing my Pdb te kry met die hoop dat SharePoint se 12 Die korf sou toon die stapel spoor, but no luck. I don’t know if it’s possible and if someone does, laat weet my asseblief 🙂

Ek weet dit is moontlik om Skryf jou eie log boodskappe aan die 12 Hive. Frankly, Ek wou iets 'n bietjie minder skrikwekkend en vinniger te implementeer.

Dit het by my opgekom dat ek kon ten minste 'n paar basiese spoor inligting deur te vang en weer gooi generiese uitsonderings soos hierdie:

  probeer {
    UpdateEditionDate(eienskappe);
  }
  vang (Uitsondering en)
  {
    gooi nuwe Uitsondering("Planner, UpdateEditionDate(): Uitsondering: [" + e.ToString() + "].");
  }

Dit het in die 12 Hive thusly:

Fout met laai en hardloop gebeurtenis ontvanger Conchango.xyzzyEventReceiver in Xyzzy, Weergawe = 1.0.0.0, Culture = neutral, PublicKeyToken = blahblahblah. Additional information is below. : Planner, UpdateEditionDate(): Uitsondering: [System.NullReferenceException: Object verwys nie na 'n geval van 'n voorwerp. at Conchango.xyzzyManagementEventReceiver.UpdateEditionDate(SPItemEventProperties eienskappe) at Conchango.xyzzyManagementEventReceiver.Dispatcher(SPItemEventProperties eienskappe, String eventDescription)].

Dit het my al die besonderhede wat ek nodig het dat die spesifieke probleem op te spoor, en ek verwag om dit te gebruik 'n baie vorentoe.

</einde>

Skryf in op my blog!

Oplossing: SPQuery soek nie na dopgehou

Die afgelope week het ek die implementering van 'n "ontwikkelende" solution for a client that uses BDC and SPQuery and ran into some difficulty using SPQuery against a document library containing folders. Bottom line: wys "rekursiewe" die oog kenmerk van die navraag.

My scenario:

  • Op Maandag, Ek laai 'n dokument en verskaf 'n meta data.
  • Die volgende week, I upload a new document. Much of this new document’s meta data is based on the document I uploaded on Monday (wat ons noem die "meester-dokument").
  • Ons het 'n web fasade wat 'n BDC-vriendelike koppelvlak tot die lys sodat gebruikers kan maklik deur middel van 'n titel te soek wat Maandag-dokument vind.
  • A BDC data column provides a friendly user interface. (Dit is deel van my poging om by die gebruik van BDC vir 'n meer vriendelike Lookup kolom).

Die finale BDC gevel diens gebruik 'n navraag, soos die soek om te doen.:

 // U2U hulpmiddel om te help in die opwekking van hierdie CAML navraag.
      oQuery.Query =
        "<Waar>";

      indien (titleFilter.Length > 0)
        oQuery.Query   =
          "  <En>";

      oQuery.Query   =
        "    <En>" +
        "      <Geq>" +
        "        <FieldRef Naam =  "DocumentId " />" +
        "        <Waarde Tipe =  "teks ">" + MinID + "</Waarde>" +
        "      </Geq>" +
        "      <Leq>" +
        "        <FieldRef Naam =  "DocumentId " />" +
        "        <Waarde Tipe =  "teks ">" + maxId + "</Waarde>" +
        "      </Leq>" +
        "    </En>";

      indien (titleFilter.Length > 0)
        oQuery.Query   =
          "    <Bevat>" +
          "      <FieldRef Naam =  "Titel " />" +
          "      <Waarde Tipe =  "teks ">" + titleFilter + "</Waarde>" +
          "    </Bevat>" +
          "  </En>";
      oQuery.Query   =
        "</Waar>";

Gedurende die eerste fase van die ontwikkeling, this worked great. Egter, ons bekendgestel dopgehou in die gids 'n paar probleme op te los en skielik, 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, ons 'n gids skep wat gebaseer is op die lys-item se ID en dan beweeg die lêer daar (Ek het geskryf oor hier; ons het gemengde resultate met hierdie benadering nie, maar oor die algemeen, dit goed werk). 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["Dokumente"];

SPQuery oQuery = nuwe SPQuery();

Ek plaas 'n konstruktor wat die oog gespesifiseer:

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

SPQuery oQuery = nuwe SPQuery(oList.Views["Alle dokumente"]);

Dit is die probleem opgelos het en ek het my resultate te kry.

I then added the CONTAINS operator into the mix and it broke again. It turns out that the CONTAINS operator, so ver as wat ek kan sê, nie werk nie met die oog op dieselfde wyse as die van 'n eenvoudiger GEQ / LEQ operators. I did some searching and learned that the query’s ViewAttributes should be set to "Recursive", soos in:

oQuery.ViewAttributes = "Scope = " Rekursiewe "";

That solved the problem for CONTAINS. In werklikheid, dit is ook my oorspronklike soek probleem opgelos en as ek het vermeld die rekursiewe kenmerk die eerste keer, Ek wil nie gehardloop het nie weer in die saak.

Die feit dat 'n oog-gebaseerde SPQuery werk vir sommige operateurs (GEQ / LEQ) en ander nie (BEVAT), tesame met die feit dat KPI's nie lyk te alle saam met die gids-bevattende dokument biblioteke, lei my om te glo dat SPQuery het 'n paar ortogonaliteit kwessies.

Spesiale dank:

  • Die goeie mense by U2U en hulle navraag instrument.
  • Michael Hoffer se groot "leer deur te doen" blog post, kommentaar en antwoorde.

</einde>

Skryf in op my blog!

MOSS KPI fout? Lys aanwyser wat gekoppel is aan Document Library met dopgehou

UPDATE 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. Ek beskryf wat in 'n bietjie meer detail hier.

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 (met behulp van 'n tegniek wat soortgelyk is aan wat ek geskryf het oor hier). We’ve successfully navigated around the potential issues caused by event receivers that rename uploaded files (hoofsaaklik omdat gebruikers nooit begin hul dokument deur te kliek op die "nuwe" maar eerder die skep van die Dokumente plaaslik en dan oplaai).

Die meta data vir hierdie dokumente sluit in 'n Ja / Nee site kolom genaamd "Dringende" and another site column called "Status". We need to meet a business requirement that shows the percentage of "Urgent" dokumente wie se status "In behandeling".

Dit is gewoonlik maklik om te doen en ek beskryf iets baie soos hierdie by die SharePoint Beagle met baie van die skerm skote, as jy geïnteresseerd is.

In 'n neutedop, Ek het die volgende:

  • Skep 'n uitsig op die doc biblioteek "Hangende geroep".
  • Stel die oog op die struktuur van die gids te ignoreer.
  • Skep 'n KPI Lys.
  • Skep 'n aanduiding in die lys wat verwys na die doc lib en dat "Hangende" sien.

This simply does not work. The KPI shows my target (bijv. vyf dringende) but always shows the actual number of urgent documents as zero. Paradoxically, As jy boor tot in die besonderhede, 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:

beeld

Die bogenoemde screen shot toon duidelik dat daar is twee dokumente in die oog, maar die "waarde" is one. The "CamlSchema" met 'n leeg dokument id is in die wortel-lêergids en die ander is in 'n lêergids met die naam "84".

Dit lyk my dat selfs al het u 'n oog, Die KPI nie eer die "Wys al die items sonder dopgehou nie" stel en in plaas, beperk is tot die hoofdmap.

As ek verkeerd is, asb vir my 'n lyn of 'n opmerking verlaat.

</einde>

Skryf in op my blog!

Technorati Tags:

Oplossing vir Probleem: “FileNotFoundException” Met my Feature Ontvanger.

I was working on a feature last week that would add some event receivers to a specific list instance. (Ek blog 'n bietjie oor daardie lys ontvanger hier).

Met die opdrag, Ek kon die funksie met geen fout installeer (maar sien hieronder vir die verborge fout). When I tried to deploy the feature on the site, MOSS complained of a "FileNotFoundException" fout. This blog entry describes how I solved it.

Dit is die fout wat MOSS het vir my gewys in die webblaaier:

Feature ‘b2cb42e3-4f0a-4380-aaba-1ef9cd526f20’ could not be installed because the loading of event receiver assembly "xyzzyFeatureReceiver_0" misluk: System.IO.FileNotFoundException: Could not load file or assembly ‘xyzzyFeatureReceiver_0’ of een van sy afhanklikhede. Die stelsel kan nie vind die gekose lêer.
File name: ‘xyzzyFeatureReceiver_0’
at System.Reflection.Assembly.nLoad(AssemblyName lêernaam, String kodebasis, Getuienis assemblySecurity, Vergadering locationHint, StackCrawlMark& stackMark, Boole throwOnFileNotFound, Boole forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Getuienis assemblySecurity, StackCrawlMark& stackMark, Boole forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Getuienis assemblySecurity, StackCrawlMark& stackMark, Boole forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()
WRN: Vergadering binding registrasie is afgeskakel.
Vergadering bind mislukking versuip in staat te stel om, stel die register waarde [HKLM Software Microsoft Fusion!EnableLog] (DWORD) aan 1.
Let daarop: Daar is 'n prestasie straf wat verband hou met die vergadering bind versuim om te meld.
Om hierdie funksie af te skakel, verwyder die register waarde [HKLM Software Microsoft Fusion!EnableLog].

Oplos van probleme met kwessies met Windows SharePoint Services.

Ek weet hoe om doelbewus veroorsaak dat die fout: don’t install the assembly in the GAC. Maar, 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% gemaklik om dit te doen, want ek het nog altyd gedink dat gacutil bestaan ​​vir 'n rede … so I tried that. It made no difference.

Ek het die Inter en het gevind dat hierdie post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2243677&SiteID=1

Die plakkaat gebeur te word met behulp van dieselfde wortel bietjie van die kode (van die binnekant van WSS boek van hierdie lys) so that was a hopeful sign. Egter, die voorstel van die versiering van die vergadering met 'n [vergadering: ] 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.

Volgende, I went to the trouble of enabling the "assembly bind failure log" (na aanleiding van die hulpvaardig en akkurate instruksies) 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. Maar … dit sal nie soek vir dit in die 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" funksie b2cb42e3-4f0a-4380-aaba-1ef9cd526f20: System.ArgumentNullException: Waarde kan nie nul wees.
Parameter naam: tipe
at System.Activator.CreateInstance(Tik, Boole nonPublic)
at System.Activator.CreateInstance(Tik)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

Oplos van probleme met kwessies met Windows SharePoint Services.

Tyd vir 'n laaste reis na die Inter!

Hierdie keer het ek uitvind, voorspelbaar genoeg, that MOSS issues this error because the assembly is not in GAC.

Ek wil iets positiefs uit te kry en probeer om te voel 'n bietjie trots op die feit dat ek geskep het Die Fugitive van MSIL gemeentes, but it’s not working. I’m just plain annoyed. I find myself muttering "chicken or the egg" onder my asem.

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" maar kan nie vind een).

Ek installering van die funksie en dit aktiveer en … dit werk! So, na al, I had to basically ‘reboot’ my project. Dit is 'n ander rede waarom ek haat rekenaars.

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. Vir een of ander rede, I did not use the -force option when I installed the new project. Hierdie keer, Ek het eintlik, truly forget to copy this new project’s assembly into the GAC. As 'n gevolg, I received that "FielNotFoundException" fout. Hierdie keer, Ek het dit van stsadm, not when I tried to activate the feature via the web browser. So, -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.

</einde>

Vinnige & Maklik: Herbenoem Opgelaai lêer SharePoint Object Model Via 'n gebeurtenis Ontvanger

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

UPDATE 2: In my huidige projek, users always upload documents. As 'n gevolg, 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() receiver looks for a valid value there before actually performing the rename and since then, 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()" metode. In plaas daarvan, we use "MoveTo(…)". Here is a minimal bit of code to accomplish this:

 openbare oorheers nietig ItemAdded(SPItemEventProperties eienskappe)
        {
            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.

This is a more useful version that does the same thing, but assigns the name of the file to "Title":

 openbare oorheers nietig ItemAdded(SPItemEventProperties eienskappe)
        {
            DisableEventFiring();

            // Assign the title of this item to the name of file itself.
 // NOTA: This assignment must take place before we modify the file itself.
 // Calling update() on the SPFile seems to invalidate the properties in
 // some sense.  Updates to "Title" failed until that change (and update() call)
 // were moved in front of the change to the file name.
            properties.ListItem["Title"] = properties.ListItem.File.Name;

            properties.ListItem.Update();

            SPFile f = properties.ListItem.File;

            // Get the extension of the file.  We need that later.
 string spfileExt = nuwe FileInfo(f.Name).Extension;

            // Rename the file to the list item's ID and use the file extension to keep
 // that part of it intact.
            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
                "/" + properties.ListItem["ID"] + spfileExt);

            // Commit the move.
            f.Update();

            EnableEventFiring();
        }

Vinnige Wenk: Inhoud Query Web Deel, Soek Kolom Waarde en XSL

Ek het 'n kolom naam in 'n inhoud-tipe, genaamd "Real Estate Plek".

Hierdie kolom is van die tipe "lookup".

Ek het verander <CommonViewFields> en ItemStyle.xsl die kolom om aan te toon.

'N eenvoudige <xsl:waarde van kies =…> . Retour terug 'n interne waarde wat ordinale posisie data, soos:

1;#Miami

Die mens-waarde te kry, Gebruik xsl substring-na, soos aangedui:

<xsl:, (@ Real_x005F_x0020_Estate_x005F_x0020_Location, '#') "> (@ Real_x005F_x0020_Estate_x005F_x0020_Location,’#’)"></xsl:waarde van>

Gebruik hierdie tegniek wanneer jy besig is met die opsoektabel waardes in XSL-transforms en nodig het om die mens-waarde te kry.

<einde />

Technorati Tags: , ,

Vinnige en maklike: Bepaal Interne kolom naam van 'n kolom Site

UPDATE: Jeremy Thake blog oor en sit 'n paar kode vir 'n konsole aansoek wat interne name toon.

Ek het probeer om 'n inhoud navraag web deel te kry om 'n vervaldatum van 'n taak om te wys, en omdat die skerm van 'n etiket "vervaldatum", Ek aanvaar dat die kolom naam te gebruik in <CommonViewFields> "Due_x0020_Date".

Verkeerd!

Die werklike kolom naam in hierdie geval was "DueDate".

Hoe het ek dit vind? I re-read Heather Salomo se blog inskrywing op die wysiging van CQWP to show additional columns of data. She describes this process at step #13. Trust it. It’s correct. Ten minste, it was correct for me. I did not trust it at first for another column with a much longer name.

Ek sê "Vertrou dit" because I did not trust it and probably wasted near two hours butting my head up against a wall. After I resolved the "DueDate" naam, Ek wou 'n ander veld toe te voeg tot <CommonViewFields>. Using the Solomon technique, Ek was besig om 'n kolom naam soos "XYZ_x0020_Project_x0020_Due_x00".

Ek het gedink, 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.

Bonus punt: Wanneer ek besig was met die CQWP, as ek by 'n slegte interne naam <CommonViewFields>, the CQWP would tell me that the query had returned no results. Maar, as ek by 'n datatipe aan die gebied se naam, 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, Maar toe ek probeer het om die waarde daarvan om te wys, I would always get a blank.

Dit het nie masker die fout:

<CommonViewFields>Due_x0020_Date;</CommonViewfields>

Dit het verdoesel die fout:

<CommonViewFields>Due_x0020_Date,Date Time;</CommonViewfields>

</einde>