بایگانی دسته بندی: شیرپوینت توسعه

توضیح ساده: “ارزش، در محدوده مورد نظر سقوط نمی کند.”

تکمیلی: An anonymous poster left a great comment about internal names. Be sure to read it.

هنگام کار با گیرنده های رویداد و کد دیگر که مراجع شیرپوینت اقلام لیست از طریق مدل شی, من اغلب مرتکب اشتباه می شوند که تولید این خطا در زمان اجرا:

خطا در بارگذاری و در حال اجرا رویداد Conchango.xyzzyEventReceiver گیرنده در xyzzy, نسخه = 1.0.0.0, فرهنگ = بی طرف, 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. اما, one simple explanation is that I’m referencing a field incorrectly. If the name of the field is "Due Date", من باید آن را مانند این در گیرنده رویداد مرجع:

properties.ListItem["Due Date"]

وقتی که من املای غلط و یا استفاده از مورد اشتباه در هنگام اشاره به زمینه, SharePoint generates the above mentioned runtime error. مثلا, این اشتباه است:

properties.ListItem["due Date"]

</پایان>

مشترک شدن در وبلاگ من.

سریع & ساده: ایجاد یک پوشه و اختصاص دادن یک نوع محتوا (یا, KPI ها و غذا خوردن آنها را بیش از حد)

به منظور کار در اطراف یک مشکل KPI من در مورد اینجا نوشت, 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) کاربران نهایی نمی دانم هر بهتر و 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. به عنوان یک نتیجه, 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 = جدید 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:

تصویر

</پایان>

مشترک شدن در وبلاگ من!

دسترسی سریع و آسان: به دریافت SPFolder از SPListItem در گیرنده رویداد

من نفرت را به آن اعتراف, 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:

خصوصی از درجه اعتبار ساقط UpdateParentFolder(SPItemEventProperties خواص)
{

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


} // UpdateParentFolder

در این مورد, 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). در عوض, go to the list item’s associated File and get the File’s folder.

</پایان>

مشترک شدن در وبلاگ من!

با این حال، یکی دیگر از رویداد گیرنده ترفند اشکالزدایی

I’m sure I’m not the first person to come up with this. اما, I haven’t noticed anyone publish a trick like this since I started paying close attention to the community last July. پس, من فکر کردم من می خواهم آن را آسان و سریع اشکال زدایی نوک ارسال.

من کار بر روی یک گیرنده رویداد آغاز شده است که برای تولید این خطا در 12 کندو:

خطا در بارگذاری و در حال اجرا رویداد Conchango.xyzzyEventReceiver گیرنده در xyzzy, نسخه = 1.0.0.0, فرهنگ = بی طرف, PublicKeyToken = blahbalhbalh. Additional information is below. : مرجع شی به یک نمونه از یک شی تنظیم نشده.

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.

من سعی کردم این راه حل به PDB من در آن وجود دارد با این امید که شیرپوینت 12 کندو ردیابی پشته را نشان می دهد, اما هیچ شانس. I don’t know if it’s possible and if someone does, لطفا اجازه دهید من می دانم 🙂

من می دانم که این امکان وجود دارد نوشتن پیام های ورود به سیستم خود را به 12 کندو. Frankly, من می خواستم چیزی کمی کمتر ترسناک و سریعتر برای پیاده سازی.

آن را به من رخ داده است که من می توانم حداقل برخی از اطلاعات اولیه اثری با فیلم برداری و دوباره پرتاب استثنا کلی مثل این:

  امتحان {
    UpdateEditionDate(خواص);
  }
  گرفتن (استثنا الکترونیکی)
  {
    پرتاب جدید استثنا("Dispatcher, UpdateEditionDate(): استثنا: [" + e.ToString() + "].");
  }

این نشان داد در 12 کندو thusly:

خطا در بارگذاری و در حال اجرا رویداد Conchango.xyzzyEventReceiver گیرنده در xyzzy, نسخه = 1.0.0.0, فرهنگ = بی طرف, PublicKeyToken = blahblahblah. Additional information is below. : اعزام کننده, UpdateEditionDate(): استثنا: [System.NullReferenceException: مرجع شی به یک نمونه از یک شی تنظیم نشده. at Conchango.xyzzyManagementEventReceiver.UpdateEditionDate(خواص SPItemEventProperties) at Conchango.xyzzyManagementEventReceiver.Dispatcher(خواص SPItemEventProperties, eventDescription رشته)].

که به من تمام جزئیات مورد نیاز برای پیگیری کردن آن مشکل خاص و من انتظار دارم به استفاده از آن را بسیار رفتن به جلو.

</پایان>

مشترک شدن در وبلاگ من!

راه حل: SPQuery Does Not Search 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. خط پایین: assign "recursive" to the view attribute of the query.

My scenario:

  • On Monday, I upload a document and supply some meta data.
  • 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 =
        "<جایی که>";

      اگر (titleFilter.Length > 0)
        oQuery.Query  =
          "  <و>";

      oQuery.Query  =
        "    <و>" +
        "      <Geq>" +
        "        <FieldRef Name=\"DocumentId\" />" +
        "        <Value Type=\"Text\">" + minId + "</ارزش>" +
        "      </Geq>" +
        "      <Leq>" +
        "        <FieldRef Name=\"DocumentId\" />" +
        "        <Value Type=\"Text\">" + maxId + "</ارزش>" +
        "      </Leq>" +
        "    </و>";

      اگر (titleFilter.Length > 0)
        oQuery.Query  =
          "    <شامل>" +
          "      <FieldRef Name=\"Title\" />" +
          "      <Value Type=\"Text\">" + titleFilter + "</ارزش>" +
          "    </شامل>" +
          "  </و>";
      oQuery.Query  =
        "</جایی که>";

During the initial stage of development, this worked great. اما, 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 اینجا; 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", همانطور که در:

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

That solved the problem for CONTAINS. در واقع, this also solved my original search problem and if I had specified the recursive attribute the first time, I would not have run into the issue again.

The fact that a view-based SPQuery works for some operators (GEQ/LEQ) and not others (CONTAINS), coupled with the fact that KPIs don’t seem to work at all with folder-containing document libraries leads me to believe that SPQuery has some orthogonality issues.

Special Thanks:

  • The good folks at U2U and their query tool.
  • Michael Hoffer’s great "learning by doing" پست وبلاگ, comments and responses.

</پایان>

مشترک شدن در وبلاگ من!

خزه اشکال KPI? لیست شاخص با پوشه وابسته به کتابخانهی سند

تکمیلی 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 اینجا). 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".

انجام این کار معمولاً ساده است و من چیزی شبیه به این را در شیرپوینت بیگل توصیف کردم با تعداد زیادی عکس از صفحه نمایش اگر علاقه دارید.

به طور خلاصه, من زیر:

  • Create a view on the doc library called "Pending".
  • نمای را طوری پیکربندی کنید که ساختار پوشه را نادیده بگیرد.
  • یک لیست KPI ایجاد کنید.
  • Create an indicator in the list that points to the doc lib and that "Pending" دیدن.

این به سادگی کار نمی کند. KPI هدف من را نشان می دهد (e.g. پنج سند فوری) اما همیشه تعداد واقعی اسناد فوری را صفر نشان می دهد. به طور متناقض, اگر به جزئیات بپردازید, این پنج سند فوری را در لیست نشان می دهد. I created a very simple scenario with two documents, one in a folder and one not. Here is the screen shot:

تصویر

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.

</پایان>

مشترک شدن در وبلاگ من!

برچسب ها:

راه حلی برای مشکل: “FileNotFoundException” با استفاده از گیرنده بلند من.

I was working on a feature last week that would add some event receivers to a specific list instance. (من یک کمی در مورد آن گیرنده لیست بلاگ).

با استفاده از خط فرمان, من می توانم با قابلیت نصب بدون خطا (اما زیر را برای خطا مخفی). When I tried to deploy the feature on the site, MOSS complained of a "FileNotFoundException" خطا. 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’ و یا یکی از وابستگیهای آن بسته نیز. The system cannot find the file specified.
File name: ‘xyzzyFeatureReceiver_0’
at System.Reflection.Assembly.nLoad(AssemblyName نام فایل, کدهای رشته, assemblySecurity مدارک و شواهد, مجمع locationHint, StackCrawlMark& stackMark, بولی throwOnFileNotFound, forIntrospection بولی)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, assemblySecurity مدارک و شواهد, StackCrawlMark& stackMark, forIntrospection بولی)
at System.Reflection.Assembly.InternalLoad(String assemblyString, assemblySecurity مدارک و شواهد, StackCrawlMark& stackMark, 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) به 1.
یادداشت: 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. اما, 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. اما, 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.

بعد, 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. اما … 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: ارزش نمی تواند تهی.
نام پارامتر: نوع
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! پس, 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. For some reason, I did not use the -force option when I installed the new project. این بار, I did actually, truly forget to copy this new project’s assembly into the GAC. به عنوان یک نتیجه, I received that "FielNotFoundException" خطا. این بار, I got it from stsadm, not when I tried to activate the feature via the web browser. پس, -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.

</پایان>

سریع & ساده: تغییر نام فایل آپلود شده با استفاده از شیرپوینت مدل شیء از طریق یک گیرنده رویداد

تکمیلی: This works but there are significant limitations which are described in the comments. This may still be useful in some cirumstances.

تکمیلی 2: در پروژه کنونی من, users always upload documents. به عنوان یک نتیجه, 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() گیرنده به نظر می رسد برای یک مقدار معتبر وجود دارد در واقع قبل از انجام تغییر نام دهید و پس از آن, 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()" روش. در عوض, استفاده می کنیم "MoveTo(…)". Here is a minimal bit of code to accomplish this:

 عمومی نادیده گرفتن از درجه اعتبار ساقط ItemAdded(SPItemEventProperties خواص)
        {
            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.

این یک نسخه مفید تر است که می کند همان چیزی است, but assigns the name of the file to "Title":

 عمومی نادیده گرفتن از درجه اعتبار ساقط ItemAdded(SPItemEventProperties خواص)
        {
            DisableEventFiring();

            // اختصاص عنوان این آیتم به نام خود فایل.
 // توجه: این وظیفه باید قبل از فایل خود را تغییر.
 // تلفن به روز رسانی() در SPFile به نظر می رسد به ابطال خواص در
 // از بعضی جهات.  Updates to "Title" تا که تغییر شکست خورده (و به روز رسانی() صدا)
 // در مقابل تغییر را به نام فایل منتقل شدند.
            properties.ListItem["Title"] = properties.ListItem.File.Name،;

            properties.ListItem.Update();

            SPFile F = properties.ListItem.File;

            // دریافت پسوند فایل.  ما نیاز داریم که بعد از.
 رشته spfileExt = جدید FileInfo(f.Name).گسترش;

            // تغییر نام فایل به ID قلم دوم از اقلام لیست و استفاده از پسوند فایل را به نگه داشتن
 // که بخشی از آن دست نخورده.
            f.MoveTo(properties.ListItem.ParentList.RootFolder.Url +
                "/" + properties.ListItem["ID"] + spfileExt);

            // مرتکب حرکت.
            f.Update();

            EnableEventFiring();
        }

نکته سریع: محتوا قسمت وب سایت پرس و جو, مراجعه مقدار ستون و XSL

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

That column is of type "lookup".

من تغییر کرده اند <CommonViewFields> و ItemStyle.xsl برای نشان دادن ستون.

ساده <XSL:ارزش را انتخاب کنید =…> دوباره ارزش داخلی که شامل داده های جایگاه ترتیبی, مانند:

1;#میامی

برای به دست آوردن ارزش انسان دوستانه, استفاده از XSL زیر رشته پس از, به عنوان نشان داده شده است:

<XSL:value-of select="substring-after(_AT_ Real_x005F_x0020_Estate_x005F_x0020_Location به,'#')"></XSL:ارزش>

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

<پایان پیام />

برچسب ها: , ,

دسترسی سریع و آسان: تعیین نام ستون های داخلی ستون سایت

تکمیلی: جرمی Thake در مورد این بلاگ قرار داده و تا برخی از کد برای یک برنامه کنسول که نام داخلی را نشان می دهد.

من در تلاش بود برای گرفتن یک پرس و جو بخشی از محتوای وب برای نمایش تاریخ به دلیل از کار و چون برچسب روی صفحه نمایش است که "موعد مقرر", من فرض شده است که به نام ستون را در استفاده از <CommonViewFields> است "Due_x0020_Date".

اشتباه!

نام ستون واقعی در این مورد بود "DueDate".

چگونه آن را پیدا کنم? I re-read Heather وبلاگ سلیمان در اصلاح 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" نام, من می خواستم برای اضافه کردن یکی دیگر از زمینه <CommonViewFields>. Using the Solomon technique, I was getting a column name like "XYZ_x0020_Project_x0020_Due_x00".

با خودم فکر کردم, 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.

نکته: هنگامی که من با CQWP مشغول به کار بود, اگر من اضافه شده یک نام بد داخلی <CommonViewFields>, the CQWP would tell me that the query had returned no results. اما, اگر من اضافه شده یک نوع داده به نام حوزه, 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, اما زمانی که من سعی کردم برای نشان دادن ارزش آن, I would always get a blank.

این خطا ماسک نیست:

<CommonViewFields>Due_x0020_Date;</CommonViewfields>

این ماسک خطا:

<CommonViewFields>Due_x0020_Date,DATETIME;</CommonViewfields>

</پایان>