Arkivji tal-Kategorija: SharePoint Iżvilupp

Sempliċi Spjegazzjoni: “Valur ma taqax fi ħdan il-firxa mistennija.”

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

Meta taħdem ma 'riċevituri avveniment u l-kodiċi oħra li SharePoint oġġetti referenzi lista permezz tal-mudell oġġett, I spiss jagħmlu żbalji li jiġġeneraw dan l-iżball fil runtime:

Jtellgħu u jħaddmu Żball avveniment riċevitur Conchango.xyzzyEventReceiver fil xyzzy, Verżjoni = 1.0.0.0, Kultura = newtrali, 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. Madankollu, one simple explanation is that I’m referencing a field incorrectly. If the name of the field is "Due Date", Ikolli referenza hija bħal dan riċevitur avveniment:

properties.ListItem["Due Date"]

Meta I misspell jew jużaw il-każ żbaljat meta referenzar-qasam, SharePoint generates the above mentioned runtime error. Per eżempju, dan hu ħażin:

properties.ListItem["due Date"]

</aħħar>

Abbona għall-blog tiegħi.

Quick & Easy: Oħloq Folder u Jassenja Tip Kontenut (Jew, Have KPIs tiegħek u Kul Them Too)

In order to work around a KPI problem I wrote about here, 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) the end users don’t know any better and 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, which isn’t the end of the world.

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. Bħala riżultat, it’s a piece of cake to keep the parent folder’s 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 = ġdid SPContentTypeId("0x0120002A666CAA9176DC4AA8CBAA9DC6B4039F");
  addedFolder.Item["Content Type ID"] = kpiCT;
  addedFolder.Item.Update();

To locate the actual Content Type ID, I accessed that content type via site settings and copy/pasted it from the URL as shown:

immaġni

</aħħar>

Abbona għall-blog tiegħi!

Quick u Easy: Niżżel l-SPFolder ta 'SPListItem fi Receiver Event

Ddejjaqni li jammettu li, 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:

privat null UpdateParentFolder(SPItemEventProperties proprjetajiet)
{

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


} // UpdateParentFolder

F'dan il-każ, Jien jaħdmu ma 'librerija dokument u l-proprjetajiet huma ġejjin minn avveniment ItemAdded.

Il-trick huwa li inti ma tistax tikseb l-SPFolder 'l-oġġett direttament mill-oġġett innifsu (I.E. properties.ListItem.Folder huwa null). Minflok, mur File assoċjati l-oġġett lista u jiksbu folder tal-fajl.

</aħħar>

Abbona għall-blog tiegħi!

Énième Event Receiver Trick Debug

I’m sure I’m not the first person to come up with this. Madankollu, I haven’t noticed anyone publish a trick like this since I started paying close attention to the community last July. Allura, Ħsibt I d jimpustah dan il-ponta debug malajr u faċli.

Jien jaħdmu fuq riċevitur każ li bdew jiġġeneraw dan l-iżball fil- 12 doqqajs:

Jtellgħu u jħaddmu Żball avveniment riċevitur Conchango.xyzzyEventReceiver fil xyzzy, Verżjoni = 1.0.0.0, Kultura = newtrali, PublicKeyToken = blahbalhbalh. Additional information is below. : Referenza Għan mhux stabbiliti għal istanza ta 'oġġett.

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.

I ppruvaw din is-soluzzjoni tikseb PDB tiegħi fil hemm ma 'jittama li l-SharePoint 12 doqqajs kieku juru t traċċa munzell, iżda l-ebda xortih. I don’t know if it’s possible and if someone does, jekk jogħġbok let me know 🙂

Naf huwa possibbli li jiktbu messaġġi tiegħek log stess għall- 12 doqqajs. Frankly, I riedu xi ftit inqas scary u aktar malajr biex jimplimentaw.

Dan ġara lili li I jistgħu għall-inqas nikseb xi traċċa informazzjoni bażika mill-qbid u mill-ġdid jitfg eċċezzjonijiet ġeneriċi bħal dan:

  jippruvaw {
    UpdateEditionDate(proprjetajiet);
  }
  qabda (Eċċezzjoni u)
  {
    tarmi ġdid Eċċezzjoni("Dispatcher, UpdateEditionDate(): Eċċezzjoni: [" + e.ToString() + "].");
  }

Dan wera up fil- 12 doqqajs thusly:

Jtellgħu u jħaddmu Żball avveniment riċevitur Conchango.xyzzyEventReceiver fil xyzzy, Verżjoni = 1.0.0.0, Kultura = newtrali, PublicKeyToken = blahblahblah. Additional information is below. : Dispatcher, UpdateEditionDate(): Eċċezzjoni: [System.NullReferenceException: Referenza Għan mhux stabbiliti għal istanza ta 'oġġett. at Conchango.xyzzyManagementEventReceiver.UpdateEditionDate(Proprjetajiet SPItemEventProperties) at Conchango.xyzzyManagementEventReceiver.Dispatcher(Proprjetajiet SPItemEventProperties, EventDescription String)].

Li tatni l-dettall I meħtieġa biex jillokalizzaw din il-problema partikolari u nistenna li jużawh ħafna miexi 'l quddiem.

</aħħar>

Abbona għall-blog tiegħi!

Soluzzjoni: SPQuery Does Mhux Fittex 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" għall-attribut dawl tal-mistoqsija.

Xenarju tiegħi:

  • Nhar it-Tnejn, I ittella 'dokument u jissupplixxi xi metadata.
  • Il-ġimgħa li ġejja, 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").
  • Imxejna ħolqot faċċata servizz web li jipprovdi interface BDC-friendly mal-lista sabiex l-utenti jistgħu faċilment jillokalizza dak id-dokument it-Tnejn permezz ta 'tfittxija titolu.
  • A BDC data column provides a friendly user interface. (Din hija parti mill tentattiv tiegħi fl-użu BDC għal kolonna Lookup aktar faċli).

Il-finali BDC servizz façade juża mistoqsija bħal din tagħmel l-Lookup:

 // Użati għodda U2U biex jgħinu fil-ġenerazzjoni din il-mistoqsija CAML.
      oQuery.Query =
        "<Fejn>";

      jekk (titleFilter.Length > 0)
        oQuery.Query   =
          "  <U>";

      oQuery.Query   =
        "    <U>" +
        "      <Geq>" +
        "        <FieldRef Name=\"DocumentId\" />" +
        "        <Value Type=\"Text\">" + MinID + "</Valur>" +
        "      </Geq>" +
        "      <Leq>" +
        "        <FieldRef Name=\"DocumentId\" />" +
        "        <Value Type=\"Text\">" + maxId + "</Valur>" +
        "      </Leq>" +
        "    </U>";

      jekk (titleFilter.Length > 0)
        oQuery.Query   =
          "    <Fih>" +
          "      <FieldRef Name=\"Title\" />" +
          "      <Value Type=\"Text\">" + titleFilter + "</Valur>" +
          "    </Fih>" +
          "  </U>";
      oQuery.Query   =
        "</Fejn>";

Matul l-istadju inizjali ta 'żvilupp, this worked great. Madankollu, aħna introduċiet folders fil-direttorju biex isolvu xi problemi u f'daqqa waħda, 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, aħna toħloq folder bbażata fuq ID-oġġett lista u mbagħad jimxu l-fajl hemmhekk (I kiteb dwar dan hawn; aħna kellna riżultati mħallta ma dan l-approċċ, iżda fuq kollox, huwa xogħol tajjeb). 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 = ġdid SPQuery();

I minflok jintuża kostruttur dik speċifikata ħsieb:

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

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

Li tissolva l-problema u I bdiet tikseb riżultati tiegħi.

I then added the CONTAINS operator into the mix and it broke again. It turns out that the CONTAINS operator, safejn peux, ma taħdem ma 'l-opinjoni l-istess mod bħall-a GEQ sempliċi / LEQ operators. I did some searching and learned that the query’s ViewAttributes should be set to "Recursive", kif fil-:

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

That solved the problem for CONTAINS. Fil-fatt, dan solvuti wkoll problema tiegħi tfittxija oriġinali u jekk kelli speċifikat l-attribut jirrikorri l-ewwel darba, I ma kien ikun imur lejn il-kwistjoni mill-ġdid.

Il-fatt li SPQuery bbażata view xogħlijiet għal ċerti operaturi (GEQ/LEQ) u mhux oħrajn (FIH), flimkien mal-fatt li KPIs ma jidhirx li jaħdmu fil-livelli kollha mal-libreriji li fihom folder dokument twassalni biex jemmnu li SPQuery għandha xi kwistjonijiet orthogonality.

Grazzi speċjali:

</aħħar>

Abbona għall-blog tiegħi!

MOSS KPI bug? Indikatur Lista Marbuta biex Dokument Librerija Bil folders

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. I described that in a little more detail here.

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 (using a technique similar to what I wrote about hawn). 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" but instead create the docs locally and then upload them).

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".

This is usually simple to do and I described something very much like this at the SharePoint Beagle with lots of screen shots if you’re interested.

In a nutshell, Jien għamilt dan li ġej:

  • Create a view on the doc library called "Pending".
  • Configure the view to ignore folder structure.
  • Create a KPI List.
  • Create an indicator in the list that points to the doc lib and that "Pending" ħsieb.

This simply does not work. The KPI shows my target (e.g. five urgent documents) but always shows the actual number of urgent documents as zero. Paradoxically, if you drill down to the details, 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:

immaġni

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".

It appears to me that even though you specify a view, the KPI doesn’t honor the "show all items without folders" setting and instead, confines itself to the root folder.

If I’m wrong, please drop me a line or leave a comment.

</aħħar>

Abbona għall-blog tiegħi!

Tags:

Soluzzjoni għall-problema: “FileNotFoundException” Bil Riċevitur Karatteristika Tiegħi.

I was working on a feature last week that would add some event receivers to a specific list instance. (I blogged ftit dwar dak riċevitur lista hawn).

Bl-użu kmand tal-linja, I tista 'tinstalla l-karatteristika bl-ebda żball (imma ara hawn taħt għal-iżball moħbija). When I tried to deploy the feature on the site, MOSS complained of a "FileNotFoundException" żball. This blog entry describes how I solved it.

This is the error that MOSS showed me in the web browser:

Feature ‘b2cb42e3-4f0a-4380-aaba-1ef9cd526f20’ could not be installed because the loading of event receiver assembly "xyzzyFeatureReceiver_0" failed: System.IO.FileNotFoundException: Could not load file or assembly ‘xyzzyFeatureReceiver_0’ or one of its dependencies. The system cannot find the file specified.
File name: ‘xyzzyFeatureReceiver_0’
at System.Reflection.Assembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) li 1.
Innota: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

Troubleshoot issues with Windows SharePoint Services.

I know how to deliberately cause that error: don’t install the assembly in the GAC. Iżda, 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% comfortable doing that because I always thought that gacutil existed for a reason … so I tried that. It made no difference.

I searched the Internets and found this post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2243677&SiteID=1

The poster happened to be using the same root bit of code (from the Inside WSS book from this list) so that was a hopeful sign. Madankollu, the suggestion of decorating the assembly with an [assembly: ] 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.

Li jmiss, I went to the trouble of enabling the "assembly bind failure log" (following the helpful and accurate instructions provided) 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. Iżda … it won’t search for it in the 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" for feature b2cb42e3-4f0a-4380-aaba-1ef9cd526f20: System.ArgumentNullException: Valur ma jistax ikun null.
Isem Parametru: tip
at System.Activator.CreateInstance(Type type, Boolean nonPublic)
at System.Activator.CreateInstance(Type type)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

Troubleshoot issues with Windows SharePoint Services.

Time for one last trip to the Internets!

This time I find out, predictably enough, that MOSS issues this error because the assembly is not in GAC.

I want to get something positive out of this and try to feel a little proud that I’ve created the Fugitive of MSIL assemblies, but it’s not working. I’m just plain annoyed. I find myself muttering "chicken or the egg" under my breath.

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" but can’t find one).

I install the feature and activate it and … it works! Allura, after all that, I had to basically ‘reboot’ my project. This is another reason why I hate computers.

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. Għal xi raġuni, I did not use the -force option when I installed the new project. Din id-darba, I did actually, truly forget to copy this new project’s assembly into the GAC. Bħala riżultat, I received that "FielNotFoundException" żball. Din id-darba, I got it from stsadm, not when I tried to activate the feature via the web browser. Allura, -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.

</aħħar>

Quick & Easy: Semmi File Uploaded Jużaw Object Model SharePoint permezz ta 'Receiver Event

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

UPDATE 2: Fil-proġett kurrenti tiegħi, users always upload documents. Bħala riżultat, 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() riċevitur jistenna għal valur validu hemm qabel fil-fatt twettaq il semmi mill-ġdid u minn dakinhar, 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()" metodu. Minflok, nużaw "MoveTo(…)". Here is a minimal bit of code to accomplish this:

 pubbliku override null ItemAdded(SPItemEventProperties proprjetajiet)
        {
            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.

Din hija verżjoni aktar utli li ma l-istess ħaġa, but assigns the name of the file to "Title":

 pubbliku override null ItemAdded(SPItemEventProperties proprjetajiet)
        {
            DisableEventFiring();

            // Jassenja l-titolu ta 'din il-partita għall-isem tal-fajl innifsu.
 // NOTA: Din il-ħidma għandha sseħħ qabel we jimmodifika l-file nnifsu.
 // Sejħat aġġornament() fuq il-SPFile jidher li tinvalida l-proprjetajiet
 // xi sens.  Updates to "Title" naqset sakemm dik il-bidla (u l-aġġornament() sejħa)
 // tmexxew quddiem il-bidla għall-isem ta 'fajl.
            properties.ListItem["Title"] = Properties.ListItem.File.Name;

            properties.ListItem.Update();

            SPFile f = properties.ListItem.File;

            // Niżżel l-estensjoni tal-fajl.  Għandna bżonn li aktar tard.
 string spfileExt = ġdid File Info(f.Name).Estensjoni;

            // Semmi mill-ġdid l-fajl lill ID-oġġett lista u jużaw l-estensjoni fajl biex iżommu
 // li intatta parti minnu.
            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
                "/" + properties.ListItem["ID"] + spfileExt);

            // Jimpenjaw il-moviment.
            f.Update();

            EnableEventFiring();
        }

Tip Quick: Parti kontenut Web Mistoqsija, Lookup Valur Kolonna u XSL

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

That column is of type "lookup".

I immodifikaw <CommonViewFields> u ItemStyle.xsl biex juru l-kolonna.

A sempliċi <XSL:valur tal tagħżel =…> prospetti lura valur intern li tinkludi data tal-posizzjoni ordinal, bħal:

1;#Miami

Biex tikseb il-valur tal-bniedem-friendly, użu XSL substring-wara, kif muri:

<XSL:value-of select="substring-after(@ Real_x005F_x0020_Estate_x005F_x0020_Location,"#")"></XSL:il-valur tal->

Uża din it-teknika meta inti taħdem ma 'valuri Lookup fil jittrasforma XSL u jeħtieġ li jiksbu l-valur tal-bniedem-friendly.

<aħħari />

Tags: , ,

Quick u Easy: Iddetermina Intern Kolonna Isem ta 'Kolonna Sit

UPDATE: Jeremy Thake has blogged about this and put up some code for a console application that shows internal names.

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 jassumi li l-isem kolonna għall-użu fil- <CommonViewFields> is "Due_x0020_Date".

Wrong!

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

How did I find it? I re-read Heather Solomon’s blog entry on modifying CQWP to show additional columns of data. She describes this process at step #13. Trust it. It’s correct. Mill-inqas, 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" isem, I wanted to add another field to <CommonViewFields>. Using the Solomon technique, I was getting a column name like "XYZ_x0020_Project_x0020_Due_x00".

I thought to myself, 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 tip: When I was working with the CQWP, if I added a bad internal name to <CommonViewFields>, the CQWP would tell me that the query had returned no results. Iżda, if I added a data type to the field name, 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, but when I tried to display its value, I would always get a blank.

This did not mask the error:

<CommonViewFields>Due_x0020_Date;</CommonViewfields>

This did mask the error:

<CommonViewFields>Due_x0020_Date,DateTime;</CommonViewfields>

</aħħar>