Kategorija Arhiva: SharePoint razvoj

Jednostavno objašnjenje: “Vrijednost ne padne unutar očekivanog raspona.”

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

Prilikom rada s događaja prijemnika i drugi kod koji reference SharePoint popis stavki putem objektni model, Ja često čine greške koje stvaraju ovu pogrešku tijekom izvršavanja:

Pogreška pri učitavanju i trčanje događaj prijemnik Conchango.xyzzyEventReceiver u xyzzy, Verzija = 1.0.0.0, Kultura = neutralni, 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. Međutim, one simple explanation is that I’m referencing a field incorrectly. If the name of the field is "Due Date", Moram ga referencirati ovako u slučaju prijemnik:

properties.ListItem["Due Date"]

Kad sam pogrešno ili koristite pogrešnu slučaj kada pozivom na polje, SharePoint generates the above mentioned runtime error. Na primjer, to je krivo:

properties.ListItem["due Date"]

</kraj>

Pretplatite se na moj blog.

Technorati Tags:

Brz & Lako: Napravite mapu i dodijeliti vrstu sadržaja (Ili, Jesu li Vaše KPI i jesti ih previše)

Kako bi zaobišli KPI problema Sam pisao o tome ovdje, 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) su krajnji korisnici ne znaju za bolje i 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, što nije kraj svijeta.

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. Kao rezultat toga, to je komad torte zadržati Roditelj mapom 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").Podmape;
  SPFolder addedFolder = srcFolders.Add(properties.ListItem.ID.ToString());
  SPContentTypeId kpiCT = novi SPContentTypeId("0x0120002A666CAA9176DC4AA8CBAA9DC6B4039F");
  addedFolder.Item["Content Type ID"] = KpiCT;
  addedFolder.Item.Update();

Da biste pronašli stvarni ID vrste sadržaja, Ja pogledana je vrsta sadržaja putem stranice postavki i copy / ga zalijepiti u URL kao što je prikazano:

slika

</kraj>

Pretplatite se na moj blog!

Technorati Tags: ,

Brzo i jednostavno: Nabavite SPFolder jednog SPListItem u Event prijemnik

Mrzim to priznati, 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:

privatni poništiti UpdateParentFolder(SPItemEventProperties Svojstva)
{

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


} // UpdateParentFolder

U tom slučaju, I’m working with a document library and the properties are coming from an ItemAdded event.

The trick is that you can’t get the SPFolder of the item directly from the item itself (i.e. properties.ListItem.Folder is null). Umjesto toga, go to the list item’s associated File and get the File’s folder.

</kraj>

Pretplatite se na moj blog!

Technorati Tags:

Još jedan događaj Debug prijemnik Trick

I’m sure I’m not the first person to come up with this. Međutim, I haven’t noticed anyone publish a trick like this since I started paying close attention to the community last July. Tako, Mislio sam da bih objaviti ga to brzo i lako ispravljanje savjet.

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

Pogreška pri učitavanju i trčanje događaj prijemnik Conchango.xyzzyEventReceiver u xyzzy, Verzija = 1.0.0.0, Kultura = neutralni, PublicKeyToken=blahbalhbalh. Additional information is below. : Objekta nije postavljena na instancu objekta.

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, javite mi 🙂

I know it’s possible to write your own log messages to the 12 košnica. 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:

  pokušati {
    UpdateEditionDate(Svojstva);
  }
  ulov (Izuzetak e)
  {
    baciti novi Izuzetak("Dispatcher, UpdateEditionDate(): Izuzetak: [" + e.ToString() + "].");
  }

This showed up in the 12 hive thusly:

Pogreška pri učitavanju i trčanje događaj prijemnik Conchango.xyzzyEventReceiver u xyzzy, Verzija = 1.0.0.0, Kultura = neutralni, PublicKeyToken=blahblahblah. Additional information is below. : Dispečer, UpdateEditionDate(): Izuzetak: [System.NullReferenceException: Objekta nije postavljena na instancu objekta. at Conchango.xyzzyManagementEventReceiver.UpdateEditionDate(SPItemEventProperties svojstva) at Conchango.xyzzyManagementEventReceiver.Dispatcher(SPItemEventProperties svojstva, 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.

</kraj>

Pretplatite se na moj blog!

Otopina: SPQuery ne traži mape

Ovaj prošli tjedan sam bio provedbi "razvija" solution for a client that uses BDC and SPQuery and ran into some difficulty using SPQuery against a document library containing folders. Bottom line: dodijeliti "rekurzivni" s pogledom na atribut upita.

Moj scenarij:

  • U ponedjeljak,, Ću uploadati dokument i dostaviti neke meta podatke.
  • Sljedeći tjedan, 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").
  • Napravili smo fasadu web servis koji pruža BDC-friendly sučelje na popisu, tako da korisnici mogu jednostavno pronaći taj dokument ponedjeljak putem naslova pretraživanje.
  • A BDC data column provides a friendly user interface. (To je dio mog pokušaja na korištenje BDC za više prijateljski Potraži stupac).

Konačna BDC fasada usluga koristi upita ovako raditi pretraživanja:

 // Koristi U2U alat za pomoć u stvaranju ovog CAML upit.
      oQuery.Query =
        "<Gdje>";

      ako (titleFilter.Length > 0)
        oQuery.Query   =
          "  <I>";

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

      ako (titleFilter.Length > 0)
        oQuery.Query   =
          "    <Sadrži>" +
          "      <FieldRef Name=\"Title\" />" +
          "      <Value Type=\"Text\">" + titleFilter + "</Vrijednost>" +
          "    </Sadrži>" +
          "  </I>";
      oQuery.Query   =
        "</Gdje>";

U početnoj fazi razvoja, this worked great. Međutim, uveli smo mape u mapu za rješavanje nekih problema i odjednom, 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, smo izradili mapu na temelju popisa stavke ID, a zatim premjestiti datoteku postoji (O tome sam pisao ovdje; imali smo mješovite rezultate s ovim pristupom, ali u cjelini, to je rad i). 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 = novi SPQuery();

I umjesto da se konstruktor koji navedenu pogled:

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

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

To je riješilo problem i počeo sam da se moje rezultate.

I then added the CONTAINS operator into the mix and it broke again. It turns out that the CONTAINS operator, koliko ja mogu reći, ne radi s pogledom na isti način kao jednostavniji geq / LEQ operators. I did some searching and learned that the query’s ViewAttributes should be set to "Recursive", kao u:

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

That solved the problem for CONTAINS. Zapravo, to također riješio moj izvorni pretragu problem i ako sam bio naveden rekurzivna značajke prvi put, Ne bih se izvoditi u pitanju opet.

Činjenica da je pogled na bazi SPQuery radi za neke operatere (Geq / Leq) a ne drugima (SADRŽI), zajedno s činjenicom da KPI ne čini uopće raditi s mape koje sadrže bibliotekama dokumenata vodi me da vjerujem da ima neke SPQuery ortogonalnost pitanja.

Posebne Hvala:

  • Dobri ljudi u U2U i njihov upit alat.
  • Michael Hoffer je super "učenje kroz rad" blog post, komentari i odgovori.

</kraj>

Pretplatite se na moj blog!

MOSS KPI bug? Popis Pokazatelj vezan za biblioteku dokumenata s mapama

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. Sam opisao da je u malo više detalja ovdje.

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 (tehnikom slično onome što sam pisao o ovdje). 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" ali umjesto toga stvaraju dokumente na lokalnoj razini, a zatim ih prenijeti).

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

To je obično jednostavan za napraviti i ja opisao nešto vrlo slično kao ovaj na SharePoint Beagle s puno zaslon metak ako vas zanima.

Ukratko, Ja sam sljedeće:

  • Create a view on the doc library called "Pending".
  • Konfiguracija pogled ignorirati strukturu mapa.
  • Napravite popis ključnih pokazatelja uspješnosti.
  • Create an indicator in the list that points to the doc lib and that "Pending" pogled.

This simply does not work. The KPI shows my target (e.g. pet hitnih dokumenti) but always shows the actual number of urgent documents as zero. Paradoxically, ako dođite do pojedinosti, 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:

slika

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

Čini mi se da, iako ste odredili pogled, the KPI doesn’t honor the "show all items without folders" postavljanja i umjesto toga, ograničava na korijenske mape.

Ako sam u krivu, molimo ispadne mi linija ili komentiranje.

</kraj>

Pretplatite se na moj blog!

Technorati Tags:

Rješenje problema: “FileNotFoundException” With My igrani prijemnik.

I was working on a feature last week that would add some event receivers to a specific list instance. (I blogged nešto o tom popisu primatelja ovdje).

Korištenje naredbenog retka, Sam mogao instalirati tu značajku bez pogreške (ali vidi dolje za skrivene greške). When I tried to deploy the feature on the site, MOSS complained of a "FileNotFoundException" pogreška. This blog entry describes how I solved it.

To je pogreška koja MOSS mi je pokazao u web pregledniku:

Feature ‘b2cb42e3-4f0a-4380-aaba-1ef9cd526f20’ could not be installed because the loading of event receiver assembly "xyzzyFeatureReceiver_0" Neuspjela: System.IO.FileNotFoundException: Could not load file or assembly ‘xyzzyFeatureReceiver_0’ ili jedan od njegovih ovisnosti. Sustav ne može pronaći navedenu datoteku.
Naziv datoteke: ‘xyzzyFeatureReceiver_0’
at System.Reflection.Assembly.nLoad(AssemblyName filename, Gudački codebase, Dokazi assemblySecurity, Skupština locationHint, StackCrawlMark& stog tlo, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Dokazi assemblySecurity, StackCrawlMark& stog tlo, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(Gudački assemblyString, Dokazi assemblySecurity, StackCrawlMark& stog tlo, Boolean forIntrospection)
at System.Reflection.Assembly.Load(Gudački assemblyString)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()
WRN: Skupština obvezujuća bilježenje isključeno.
Da biste omogućili sastavljanje prijave kvara vezanja, postavite vrijednost registra [HKLM Software Microsoft Fusion!EnableLog] (DWORD) na 1.
Primijetiti: Tu je neke performanse kazna povezana s montažnim prijave vezanje neuspjeh.
Da biste isključili tu značajku, izvadite vrijednost registra [HKLM Software Microsoft Fusion!EnableLog].

Rješavanje problema s Windows SharePoint Services.

Znam kako namjerno izazvati tu pogrešku: don’t install the assembly in the GAC. Ali, 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% ugodno, jer sam uvijek mislio da je postojala gacutil s razlogom … so I tried that. It made no difference.

Tražila sam internets i pronašao ovaj post: http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2243677&SiteID=1

Plakat se dogodilo da se koristi isti korijen malo koda (iznutra WSS knjige iz ovog popisa) so that was a hopeful sign. Međutim, Prijedlog o ukrašavanju skupštine s [montaža: ] 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.

Sljedeći, I went to the trouble of enabling the "assembly bind failure log" (nakon korisne i točne upute koje) 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. Ali … neće ga potražiti u 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" za lice b2cb42e3-4f0a-4380-aaba-1ef9cd526f20: System.ArgumentNullException: Vrijednost ne može biti nula.
Naziv parametra: tip
at System.Activator.CreateInstance(Tip putovanja, Boolean nisu za javnost)
at System.Activator.CreateInstance(Tip putovanja)
at Microsoft.SharePoint.Administration.SPFeatureDefinition.get_ReceiverObject()

Rješavanje problema s Windows SharePoint Services.

Vrijeme je za jedan posljednji izlet na internets!

Ovaj put saznam, predvidivo dovoljno, that MOSS issues this error because the assembly is not in GAC.

Želim da se nešto pozitivno iz ovog i pokušajte osjetiti malo ponosan što sam stvorio Bjegunac od MSIL skupštinama, but it’s not working. I’m just plain annoyed. I find myself muttering "chicken or the egg" ispod glasa.

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" ali ne mogu naći jedan).

Ja instalirajte značajku i aktivirali i … to radi! Tako, nakon svega što, I had to basically ‘reboot’ my project. To je još jedan razlog zašto mrzim računala.

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. Iz nekog razloga, I did not use the -force option when I installed the new project. Ovaj puta, Ja sam zapravo, truly forget to copy this new project’s assembly into the GAC. Kao rezultat toga, I received that "FielNotFoundException" pogreška. Ovaj puta, Dobio sam to od stsadm, not when I tried to activate the feature via the web browser. Tako, -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.

</kraj>

Technorati Tags: ,

Brz & Lako: Preimenovanje učitanu datoteku pomoću SharePoint Object Model putem Event prijemnik

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

UPDATE 2: U mom trenutnom projektu, users always upload documents. Kao rezultat toga, 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() prijemnik traži valjane vrijednosti tamo prije nego što zapravo obavljanje preimenovati i od tada, 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()" način. Umjesto toga, koristimo "MoveTo(…)". Here is a minimal bit of code to accomplish this:

 javni nadjačati poništiti ItemAdded(SPItemEventProperties Svojstva)
        {
            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.

To je više koristan verzija koja čini istu stvar, but assigns the name of the file to "Title":

 javni nadjačati poništiti ItemAdded(SPItemEventProperties Svojstva)
        {
            DisableEventFiring();

            // Dodjela naslov ove točke na naziv datoteke sama.
 // NAPOMENA: Ovaj zadatak se mora dogoditi prije izmijeniti datoteku.
 // Pozivanje ažuriranje() na SPFile čini se izgubiti u svojstvima
 // neki osjećaj.  Updates to "Title" nije do tog promjene (i ažuriranje() pozvati)
 // su se preselili ispred promjenu naziva datoteke.
            properties.ListItem["Title"] = Properties.ListItem.File.Name;

            properties.ListItem.Update();

            SPFile f = properties.ListItem.File;

            // Uzmite produljenje datoteke.  Trebamo kasnije.
 niz spfileExt = novi FileInfo(f.Name).Produžetak;

            // Promijenite naziv datoteke u popisu stavke ID i koristiti ekstenziju zadržati
 // da je dio njega netaknuti.
            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
                "/" + properties.ListItem["ID"] + spfileExt);

            // Obvezati na potez.
            f.Update();

            EnableEventFiring();
        }

Quick Savjet: Upit Sadržaj web-dio, Potraži Vrijednost stupca i XSL

Imam ime stupca u vrste sadržaja pod nazivom "Nekretnine Location".

Taj stupac je tipa "lookup".

Ja sam promjene <CommonViewFields> i ItemStyle.xsl prikazati stupac.

Jednostavan <XSL:vrijednost za odabir =…> vraća unutarnju vrijednost, koja uključuje podatke o položaju rednim, kao što su:

1;#Miami

Da biste dobili ljudsko-friendly vrijednost, koristiti XSL podniz poslije, kao što je prikazano:

<XSL:valuXSLf select = "podniz poslije(@ Real_x005F_x0020_Estate_x005F_x0020_Location,'#')"></XSL:vrijednost od>

Koristite ovu tehniku ​​kad god radite s lookup vrijednosti u XSL preobražava i potreban da bi se ljudi-friendly vrijednost.

<kraj />

Technorati Tags: , ,

Brzo i jednostavno: Odredite unutarnje stupac Naziv stupca web-mjesta

UPDATE: Jeremy Thake je blogged o tome i staviti neke kod za konzole primjene koja prikazuje unutarnje imena.

Ja sam težak da biste dobili web dijela za pretraživanje sadržaja za prikazivanje datuma iz zadatka i zbog zaslon label "Datum dospijeća", Pretpostavila sam da stupac ime za korištenje u <CommonViewFields> je "Due_x0020_Date".

Pogrešno!

Pravi stupac ime u ovom slučaju bio "DueDate".

Kako sam ga pronaći? I re-read Heather Solomonov blog entry o preinakama CQWP to show additional columns of data. She describes this process at step #13. Trust it. It’s correct. Barem, it was correct for me. I did not trust it at first for another column with a much longer name.

Kažem "to povjerenje" because I did not trust it and probably wasted near two hours butting my head up against a wall. After I resolved the "DueDate" ime, Htjela sam dodati još polja <CommonViewFields>. Using the Solomon technique, Sam bio uzimajući stupca ime poput "XYZ_x0020_Project_x0020_Due_x00".

Pomislio sam:, 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 savjet: Kada sam radio s CQWP, ako sam dodao unutarnje loše ime <CommonViewFields>, the CQWP would tell me that the query had returned no results. Ali, ako sam dodao vrstu podataka za polje ime, 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, ali kad sam pokušao prikazati svoju vrijednost, I would always get a blank.

To se nije prikriti pogrešku:

<CommonViewFields>Due_x0020_Date;</CommonViewfields>

Ovo nije maska ​​pogrešku:

<CommonViewFields>Due_x0020_Date,DateTime;</CommonViewfields>

</kraj>