Flokkaskjalasafn: SharePoint Þróun

Einföld útskýring: “Gildi falli ekki innan áætlaðs fjölda.”

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

Þegar unnið er með móttakara atburði og önnur númer sem tilvísanir SharePoint listi atriði í gegnum the mótmæla líkan, Ég gera oft mistök að búa til þessa villu á afturkreistingur:

Villa hleðsla og gangi móttakari Conchango.xyzzyEventReceiver í xyzzy, Útgáfa = 1.0.0.0, Menning = hlutlaus, 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. Hins, one simple explanation is that I’m referencing a field incorrectly. If the name of the field is "Due Date", Ég þarf tilvísun það svona í atburði móttakara:

properties.ListItem["Due Date"]

Þegar ég stafa vitlaust eða nota rangt mál þegar vísa á sviði, SharePoint generates the above mentioned runtime error. Til dæmis, Þetta er rangt:

properties.ListItem["due Date"]

</enda>

Gerast áskrifandi að bloggið mitt.

Technorati Tags:

Quick & Easy: Búa til möppu og tengja gerð efnis (Eða, Hafa KPIs og borða þá of)

Í því skyni að vinna í kringum KPI vandamál Ég skrifaði um hér, 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 endir notandi veit ekki betur og 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, sem er ekki the endir af the heiminum.

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. Þar af leiðandi, það er a stykki af köku til að halda foreldri mappa er meta data in sync with the KPI-driven meta data from the file itself since the plumbing is already in place. Þetta gerir mér kleift að hafa KPI og borða þau líka 🙂

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").Undirmöppur;
  SPFolder við möppu = srcFolders.Add(properties.ListItem.ID.ToString());
  SPContentTypeId kpiCT =  SPContentTypeId("0x0120002A666CAA9176DC4AA8CBAA9DC6B4039F");
  addedFolder.Item["Content Type ID"] = kpiCT;
  addedFolder.Item.Update();

Til að finna raunverulegt innihald Auðkenni, Ég nálgast þessi efni gerð í gegnum stillingar á síðuna og afrita / líma það frá vefslóð eins og sýnt:

mynd

</enda>

Gerast áskrifandi að bloggið mitt!

Technorati Tags: ,

Fljótur og Þægilegur: Fáðu SPFolder af SPListItem í Event Receiver

Ég hata að viðurkenna það, 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:

einkaaðila ógilt UpdateParentFolder(SPItemEventProperties eignir)
{

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


} // UpdateParentFolder

Í þessu tilviki, Ég er að vinna með skjal bókasafn og eignir eru að koma frá ItemAdded atburði.

The bragð er að þú getur ekki fengið SPFolder hlutarins beint frá hlutnum sjálfum (i.e. properties.ListItem.Folder er null). Staðinn, fara tengslum skrá á lista yfir atriði og fá möppu Skráin er.

</enda>

Gerast áskrifandi að bloggið mitt!

Technorati Tags:

Enn ein Receiver Event Debug Bragð

I’m sure I’m not the first person to come up with this. Hins, I haven’t noticed anyone publish a trick like this since I started paying close attention to the community last July. Svo, Ég hélt ég myndi eftir það þetta fljótleg og auðveld kemba þjórfé.

I’m working on an event receiver that started to generate this error in the 12 Hive:

Villa hleðsla og gangi móttakari Conchango.xyzzyEventReceiver í xyzzy, Útgáfa = 1.0.0.0, Menning = hlutlaus, PublicKeyToken=blahbalhbalh. Additional information is below. : Object tilvísun ekki sett til dæmis á hlut.

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 tried this solution to get my pdb in there with hopes that SharePoint’s 12 hive would show the stack trace, but no luck. I don’t know if it’s possible and if someone does, please let me know 🙂

I know it’s possible to write your own log messages to the 12 Hive. Frankly, I wanted something a little less scary and quicker to implement.

It occurred to me that I could at least get some basic trace information by catching and re-throwing generic exceptions like this:

  reyna {
    UpdateEditionDate(eignir);
  }
  veiða (Undantekning e)
  {
    kasta  Undantekning("Dispatcher, UpdateEditionDate(): Undantekning: [" + e.ToString() + "].");
  }

This showed up in the 12 hive thusly:

Villa hleðsla og gangi móttakari Conchango.xyzzyEventReceiver í xyzzy, Útgáfa = 1.0.0.0, Menning = hlutlaus, PublicKeyToken=blahblahblah. Additional information is below. : Dispatcher, UpdateEditionDate(): Undantekning: [System.NullReferenceException: Object tilvísun ekki sett til dæmis á hlut. at Conchango.xyzzyManagementEventReceiver.UpdateEditionDate(SPItemEventProperties eignir) at Conchango.xyzzyManagementEventReceiver.Dispatcher(SPItemEventProperties eignir, String eventDescription)].

That gave me all the detail I needed to track down that particular problem and I expect to use it a lot going forward.

</enda>

Gerast áskrifandi að bloggið mitt!

Lausn: SPQuery Er Ekki Leita Mappa

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. Neðsta lína: assign "recursive" að skoða eiginleiki af fyrirspurninni.

Atburðarás minn:

  • Á mánudaginn, Ég hlaða skjal og veita sumir meta gögn.
  • The following week, 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").
  • We’ve created a web service façade that provides a BDC-friendly interface to the list so that users can easily locate that Monday document via a title search.
  • A BDC data column provides a friendly user interface. (This is part of my attempt at using BDC for a more friendly Lookup column).

The final BDC façade service uses a query like this to do the lookup:

 // Used U2U tool to assist in generating this CAML query.
      oQuery.Query =
        "<Hvar>";

      ef (titleFilter.Length > 0)
        oQuery.Query  =
          "  <Og>";

      oQuery.Query  =
        "    <Og>" +
        "      <Geq>" +
        "        <FieldRef Name=\"DocumentId\" />" +
        "        <Value Type=\"Text\">" + minId + "</Gildi>" +
        "      </Geq>" +
        "      <Leq>" +
        "        <FieldRef Name=\"DocumentId\" />" +
        "        <Value Type=\"Text\">" + maxId + "</Gildi>" +
        "      </Leq>" +
        "    </Og>";

      ef (titleFilter.Length > 0)
        oQuery.Query  =
          "    <Inniheldur>" +
          "      <FieldRef Name=\"Title\" />" +
          "      <Value Type=\"Text\">" + titleFilter + "</Gildi>" +
          "    </Inniheldur>" +
          "  </Og>";
      oQuery.Query  =
        "</Hvar>";

During the initial stage of development, this worked great. Hins, we introduced folders into the directory to solve some problems and suddenly, 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, we create a folder based on the list item’s ID and then move the file there (I wrote about that hér; we’ve had mixed results with this approach but on the whole, it’s working well). 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 = SPQuery();

I instead used a constructor that specified a view:

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

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

That solved the problem and I started to get my results.

I then added the CONTAINS operator into the mix and it broke again. It turns out that the CONTAINS operator, so far as I can tell, does not work with the view the same way as the a simpler GEQ / LEQ operators. I did some searching and learned that the query’s ViewAttributes should be set to "Recursive", eins og í:

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

That solved the problem for CONTAINS. Í raun, þetta leyst einnig upprunalega leita vandamál mitt og ef ég hefði tilgreint endurkvæma eiginleiki í fyrsta sinn, Ég myndi ekki hafa keyrt inn í málið aftur.

Sú staðreynd að skoða byggir SPQuery virkar fyrir suma rekstraraðila (GEQ / LEQ) og ekki aðra (Inniheldur), ásamt þeirri staðreynd að KPIs virðist ekki vinna á öllum með möppu innihalda skjal bókasöfnum leiðir mig að trúa því að SPQuery hefur sumir orthogonality málefni.

Sérstakar þakkir:

</enda>

Gerast áskrifandi að bloggið mitt!

MOSS KPI galla? Listi Vísir bundin Document Library með möppur

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 hér). 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 með fullt af skjámyndum ef þú hefur áhuga.

Í stuttu máli, Ég gerði eftirfarandi:

  • Create a view on the doc library called "Pending".
  • Stilltu útsýnið til að hunsa möppuskipulag.
  • Búðu til KPI lista.
  • Create an indicator in the list that points to the doc lib and that "Pending" skoða.

Þetta einfaldlega gengur ekki. KPI sýnir markmiðið mitt (e.g. fimm brýn skjöl) en sýnir alltaf raunverulegan fjölda brýnna skjala sem núll. Þversagnakennt, ef þú kafar niður í smáatriðin, það sýnir fimm brýn skjöl á listanum. Ég bjó til mjög einfalda atburðarás með tveimur skjölum, einn í möppu og einn ekki. Here is the screen shot:

mynd

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.

</enda>

Gerast áskrifandi að bloggið mitt!

Technorati Tags:

Lausn á vandamáli: “FileNotFoundException” Með Receiver eiginleiki minn.

I was working on a feature last week that would add some event receivers to a specific list instance. (Ég bloggaði aðeins um að lista móttakara hér).

Using the stjórn lína, Ég gæti sett aðgerðina án villa (en sjá hér fyrir falinn villa). When I tried to deploy the feature on the site, MOSS complained of a "FileNotFoundException" villa. This blog entry describes how I solved it.

Þetta er villa sem MOSS sýndi mér í vafranum:

Feature ‘b2cb42e3-4f0a-4380-aaba-1ef9cd526f20’ could not be installed because the loading of event receiver assembly "xyzzyFeatureReceiver_0" mistókst: System.IO.FileNotFoundException: Could not load file or assembly ‘xyzzyFeatureReceiver_0’ eða eitt af ósjálfstæði. The kerfi geta ekki finna the skrá sem tilgreind.
Skrá nafn: ‘xyzzyFeatureReceiver_0’
at System.Reflection.Assembly.nLoad(AssemblyName filename, String codebase, Sönnun assemblySecurity, Samkoma locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Sönnun assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Sönnun assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()
WRN: Samkoma bindandi skógarhögg er slökkt.
Til að gera samkoma binda bilun skógarhögg, stilla skrásetning gildi [HKLM Software Microsoft Fusion!EnableLog] (DWORD) að 1.
Athugaðu: Það er einhver árangur refsing tengist samkoma binda bilun skógarhögg.
Til að kveikja þennan eiginleika af, fjarlægja skrásetning gildi [HKLM Software Microsoft Fusion!EnableLog].

Leysa mál með Windows SharePoint Services.

Ég veit hvernig á að vísvitandi valda þessi villa: don’t install the assembly in the GAC. En, 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% þægilegt að gera það vegna þess að ég hélt alltaf að gacutil verið fyrir ástæðu … so I tried that. It made no difference.

Ég leitaði internets og fann þessa færslu: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2243677&SiteID=1

Plakat varð að nota sömu rót hluti af kóða (innan frá WSS bók frá þessum lista) so that was a hopeful sign. Hins, tillögu að skreyta söfnuðinum með að [samkoma: ] 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.

Næsta, I went to the trouble of enabling the "assembly bind failure log" (fylgja gagnlegar og nákvæmar leiðbeiningar sem kveðið) 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. En … það mun ekki leita að því í 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" fyrir lögun b2cb42e3-4f0a-4380-aaba-1ef9cd526f20: System.ArgumentNullException: Gildi getur ekki verið tómt.
Viðfang nafn: tegund
at System.Activator.CreateInstance(Tegund gerð, Boolean eru almenn)
at System.Activator.CreateInstance(Tegund gerð)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

Leysa mál með Windows SharePoint Services.

Tími fyrir eitt síðasta ferð til Internets!

Þessi skipti sem ég fundið út, áreiðanlega nóg, that MOSS issues this error because the assembly is not in GAC.

Ég vil fá eitthvað jákvætt út úr þessu og reyna að finna smá stolt af því að ég hef búið á Landflótta af MSIL þingum, but it’s not working. I’m just plain annoyed. I find myself muttering "chicken or the egg" undir anda minn.

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" en getur ekki fundið einn).

Ég setja lögun og virkja það og … það virkar! Svo, eftir allt að, I had to basically ‘reboot’ my project. Þetta er önnur ástæðan af hverju ég hata tölvur.

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. For some reason, I did not use the -force option when I installed the new project. Í þetta sinn, Ég gerði í raun, truly forget to copy this new project’s assembly into the GAC. Þar af leiðandi, I received that "FielNotFoundException" villa. Í þetta sinn, Ég fékk það frá stsadm, not when I tried to activate the feature via the web browser. Svo, -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.

</enda>

Technorati Tags: ,

Quick & Easy: Endurnefna skrá innsend nota SharePoint Object Model gegnum Event Receiver

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

UPDATE 2: Í núverandi verkefni mitt, users always upload documents. Þar af leiðandi, 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() móttökutæki útlit fyrir gilt gildi þar áður en þeir framkvæma endurnefna og síðan þá, 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()" aðferð. Staðinn, við notum "MoveTo(…)". Here is a minimal bit of code to accomplish this:

 almennings forgang ógilt ItemAdded(SPItemEventProperties eignir)
        {
            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.

Þetta er meira gagni útgáfa þessi hjartarskinn the sami hlutur, but assigns the name of the file to "Title":

 almennings forgang ógilt ItemAdded(SPItemEventProperties eignir)
        {
            DisableEventFiring();

            // Úthluta titilinn á þessu atriði á nafni skrá sig.
 // ATHUGIÐ: Þessi verkefni þarf að fara fram áður en við breytt skránni sjálfri.
 // Starf uppfærslu() á SPFile virðist ógilda eiginleika í
 // sumir skilningarvit.  Updates to "Title" ekki fyrr en þessi breyting (og uppfæra() hringja)
 // voru flutt í framan the breyting til the skrá nafn.
            properties.ListItem["Title"] = Properties.ListItem.File.Name;

            properties.ListItem.Update();

            SPFile f = properties.ListItem.File;

            // Fá framlengingu á skrá.  Við þurfum að síðar.
 band spfileExt =  FileInfo(f.Name).Framlenging;

            // Endurnefna skrána til ID á lista yfir atriði og nota skrá eftirnafn til að halda
 // að hluti af því ósnortinn.
            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
                "/" + properties.ListItem["ID"] + spfileExt);

            // Skuldbinda færa.
            f.Update();

            EnableEventFiring();
        }

Quick Ábending: Efni Fyrirspurn Web Part, Leit column value og XSL

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

That column is of type "lookup".

Ég hef breytt <CommonViewFields> og ItemStyle.xsl að sýna dálk.

Einföld <XSL:gildi-af velja =…> skilar til baka innri gildi sem felur Ordinal gögn stöðu, svo sem eins og:

1;#Miami

Til að fá manna-vingjarnlegur gildi, nota XSL hlutstreng-eftir, eins og sýnt:

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

Use this technique whenever you are working with lookup values in XSL transforms and need to get the human-friendly value.

<endir />

Technorati Tags: , ,

Fljótur og Þægilegur: Ákveða Innri Column Nafn a Site dálki

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 ráð fyrir að dálkheiti til að nota í <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. At least, 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" nafn, 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. En, 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>

</enda>