Technical tips, suggestions and learnings on SharePoint.
Home » What We're Thinking » Rez's Spot
ehucsd969j
I am deleting a folder from a document library using the code:
using (SPSite tempDocLibSite = new SPSite(tempDocLibWebRootUrl)) { using (SPWeb tempDocLibWeb = tempDocLibSite.OpenWeb()) { tempDocLibWeb.AllowUnsafeUpdates = true; SPFolder tempAttachmentSubFolder = tempDocLibWeb.GetFolder(string.Format("{0}/{1}/{2}", tempDocLibName, base.ListId.ToString(), hdnTempAttachmentID.Value)); tempAttachmentSubFolder.Delete(); tempDocLibWeb.Update(); tempDocLibWeb.AllowUnsafeUpdates = false; } }
When it get’s to the highlighted line, I get the following error in the event viewer with Event ID: 6875:
Error loading and running event receiver Microsoft.SharePoint.Publishing.Internal.PublishingWebEventReceiver in Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c. Additional information is below.
: There is no file with URL 'TempAttachmentsUpload/e4486bd9-1719-4a9d-a8a1-de25924cd49a/0136561e-0d20-4b0d-b7e7-ab1e1ada6218' in this Web.
The funny thing is that the folder does exist and does get deleted.
There are lots of resources on the web about this event id for SharePoint but it looks like it’s an event that is very common for different reasons.
I am using MOSS SP1 with the December Cumulative Updates.
It looks like there is a built-in event receiver that is executing when the folder gets deleted which is causing this error. I don’t think it should cause this error and it looks like it’s a bug, hopefully someone can confirm it or correct my code. I’m not sure if it is fixed in SP2 or the April Cumulative Updates though.
[1] Technorati Profile
On my SharePoint server, I have a media directory (i.e. c:\media) full of media files that I needed to stream on the web via a SharePoint Media Player Web Part that I created (similar to [1]). At first, I just pointed an IIS virtual directory to that directory (i.e. http://<myserver>/media) and configured my web part to point to the file via the virtual directory (i.e. http://<myserver>/media/myfile.avi).
This is called Web Server Streaming and was terribly choppy and slow, you can see more details on this type of streaming at [2].
I then decided to deploy Windows Media Services on my Win 2K3 Server (ensure you have SP2 installed). I wanted to get it up and running really fast so I used a Single Server deployment. Getting this up and running turned out to be quite easy and very fast to configure. Instructions are below to get this set up.
The end results were that I configured my SharePoint Media Web Part to point to this location via a URL similar to mms://<servername>/<publishingpointname>/filename and the streaming was still a little bit choppy and slow but a little better than using a web server. When I play through window media player itself, it’s actually very smooth. I’m going to see if there is some configuration in my SharePoint Media Player Web Part that that I can tweak to make make it stream better as a next step.
**Update**
Turns out that the reason it was choppy was because in my SharePoint Media Player Web Part, I had the object and embed parameters incorrect, furthermore, the line windowlessvideo=”1” in my <embed> tag caused the control not to render in firefox. As soon as I removed it and fixed the formatting, smooth video playing ensued!
<OBJECT id="ctl00$ctl14" width="480" height="270" CLASSID="CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6" type="application/x-oleobject" codebase="http://activex.microsoft.com/activex/controls/mplayer/en/nsmp2inf.cab#Version=6,0,02,902" standby="Loading Microsoft Windows Media Player components..." align="middle" > <PARAM NAME="FILENAME" VALUE="mms://myserver/myfilepath.wmv"> <PARAM NAME="AutoStart" VALUE="False"> <PARAM NAME="z-index" VALUE="-1"> <PARAM NAME="AutoRewind" VALUE="True"> <PARAM NAME="SendOpenStateChangeEvents" VALUE="True"> <PARAM NAME="ShowControls" VALUE="True"> <PARAM NAME="ShowTracker" VALUE="True"> <PARAM NAME="showstatusbar" value="True"> <PARAM NAME="DefaultFrame" value="Slide"> <PARAM NAME="enablecontextmenu" value="True"> <PARAM NAME="TransparentAtStart" value="True"> <PARAM NAME="TransparentOnStop" value="True"> <PARAM NAME="showPositionControls" value="True"> <EMBED type="application/x-mplayer2" PLUGINSPAGE="http://www.microsoft.com/Windows/Downloads/Contents/Products/MediaPlayer/" QUALITY="high" SRC="mms://myserver/myfilepath.wmv" AUTOSTART="False" SHOWCONTROLS="True" SHOWSTATUSBAR="True" SHOWPOSITIONCONTROLS="True" SHOWTRACKER="True" ENABLECONTEXTMENU="True" WIDTH="480" HEIGHT="270" WINDOWLESSVIDEO="1" <!—Remove this--> ALIGN="middle"> </EMBED></OBJECT>
In a single-server deployment, one Windows Media server works with one or more encoders to stream content to a small group of clients. The configuration might look like this:
The single-server update is easiest because you only run through the process once. Ideally, you would have a spare computer on which you can perform a clean installation of Windows Server 2003 or Windows Server 2008 and Windows Media Services. This is beneficial because you can keep your existing server in production until all installation and testing of the new server is complete, minimizing service disruption for your viewers. If you do not have a spare computer, then be sure to make a backup of the entire system. Then choose a period where you experience low traffic on your site and proceed with the update as described later in this document.
Install Windows Media Services from Control Panel --> Add/Remove Programs --> Add/Remove Windows Components
Go to Start -> Admin Tools -> Windows Media Services
Go to Getting Started tab --> Test My Server –> Say Yes to allow client connections to test the server and ensure it works
Add a new Publishing Point (Advanced)
Select:
Go to Source tab and test a media file in that directory.
As you can see, we now are able to stream all the files in that directory using the path:
mms://<servername>/<publishing point name>/<media file path>
where:
mms://<servername>/<publishing point name>
is the “location of content” directory on the local media server.
[1] http://www.sharepointblogs.com/ajp/archive/2007/07/18/media-player.aspx
[2] http://www.microsoft.com/windows/windowsmedia/howto/articles/introhosting.aspx
[3] http://www.microsoft.com/windows/windowsmedia/howto/articles/upgradewms9s.aspx#singleserver
I haven’t found any information on this but today I tried to add a custom event handler to a list automatically when a custom field type is added to a list using the OnSaveChange() method and I got the following error:
The specified program requires a newer version of Windows. (Exception from HRESULT: 0x8007047E) at Microsoft.SharePoint.Library.SPRequestInternalClass.AddField(String bstrUrl, String bstrListName, String bstrSchemaXml, Int32 grfAdd) at Microsoft.SharePoint.Library.SPRequest.AddField(String bstrUrl, String bstrListName, String bstrSchemaXml, Int32 grfAdd)
This message doesn’t seem to be much help but what I think is happening is that SharePoint isn’t allowing simultaneous changes to a list using different SPWeb/SpSite objects. Here is a break down of my problem:
The way I was able to fix this was that instead of creating my own SPSite/SPWeb and SPList objects use the SPField object that is passed to the OnSaveChange(SPField field, bool isNewField) method and accessing the list to be updated (with the event handler) by calling the field.ParentList object:
public void OnSaveChange(SPField field, bool isNewField){ try { SPSecurity.RunWithElevatedPrivileges( delegate() { #region Delete Existing deleting event handlers first SPEventReceiverDefinitionCollection evrs =
field.ParentList.EventReceivers; List<Guid> ersToDelete = new List<Guid>(); foreach (SPEventReceiverDefinition er in evrs) { if (er.Type == SPEventReceiverType.ItemDeleting) ersToDelete.Add(er.Id); } if (evrs.Count > 0) { foreach (Guid i in ersToDelete) { evrs[i].Delete(); field.ParentList.Update(); } } #endregion string assembly = Assembly.GetExecutingAssembly().FullName; string className = typeof(DeleteIconEventHandler).FullName; field.ParentList.EventReceivers.Add(
SPEventReceiverType.ItemDeleting, assembly, className); field.ParentList.Update(); }); } catch (Exception ex) { string message = string.Format("ERROR: Method {0} had an exception while
attempting RegisterDeleteItemEventHandler : {0}", ex.Message); throw new SPException(message); }}
[1] http://msdn.microsoft.com/en-us/library/bb802857.aspx
[2] http://www.sharepointblogs.com/aaronrh/archive/2007/05/25/the-solution-to-saving-properties-in-custom-field-types.aspx
[3] http://fredmorrison.wordpress.com/category/uncategorized/
I struggled with this problem all day today. Here is my scenario:
I have created a custom SharePoint rendering template which has a bit of JavaScript in it. In the JavaScript, I want to access a string value in the Resource.resx file that is embedded to my assembly that I’m signing with a strong name and deploying to the GAC:
In my code, I can easily access the string via:
string myString = MyProjectNamespace.Properties.Resources.StringIWantToAccess
What I want to do is access that resource string from my custom .ascx web control itself which is a SharePoint rendering template that sits in the controltemplates directory. I don’t want to put my .resx resources in App_GlobalResources or App_LocalResources either. I have tried using <%$ Resources:StringIWantToAccess %>" /> and <%$ Resources:AssemblyName, StringIWantToAccess %>" /> but had no luck with this with all sorts of combinations.
It doesn’t seem that SharePoint was be able to find the resources automatically because the .ascx file is not running under the context of my custom assembly code but rather of SharePoint.
I was finally able to get it working by the following:
1. In my .ascx file reference the resource using the following code:
<% =MyProjectNamespace.Properties.Resources.StringIWantToAccess %>
2. Add a reference to my assembly on the .ascx file
<%@ Assembly Name="myAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b694fe5cf34f8401" %>
3. Change the Access Modifier to allow Public access
I’m not sure why this happens but here is the scenario:
[FormatException: Input string was not in a correct format.] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7467367 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119 System.Convert.ToInt32(String value, IFormatProvider provider) +48 Microsoft.SharePoint.SPListItem.ValueFromSafeArrayObject(Object obj, SPField fld) +785 Microsoft.SharePoint.SPListItem.GetValue(SPField fld, Int32 columnNumber, Boolean bRaw) +768 Microsoft.SharePoint.SPListItem.GetValue(String strName, Boolean bThrowException) +111 Microsoft.SharePoint.SPListItem.GetValue(String strName) +39 Microsoft.SharePoint.SPListItem.AddOrUpdateItem(Boolean bAdd, Boolean bSystem, Boolean bPreserveItemVersion, Boolean bNoVersion, Boolean bMigration, Boolean bPublish, Boolean bCheckOut, Boolean bCheckin, Guid newGuidOnAdd, Int32& ulID, Object& objAttachmentNames, Object& objAttachmentContents, Boolean suppressAfterEvents) +1228 Microsoft.SharePoint.SPListItem.UpdateInternal(Boolean bSystem, Boolean bPreserveItemVersion, Guid newGuidOnAdd, Boolean bMigration, Boolean bPublish, Boolean bNoVersion, Boolean bCheckOut, Boolean bCheckin, Boolean suppressAfterEvents) +166
After a few hours of debugging through my code and trying out other people’s ideas [3], it turns out that it doesn’t have anything to do with my code.
What I found was that if you wait a few minutes and browse to the newly created form again, you don’t get the error. It looks like once you save the file in SharePoint Designer, it takes a few minutes to propagate the page through the content database. If you browse to the page before this propagation is finished, you get the error “Input String was not in a correct format.”.
***Update***
It looks like I was still having this problem even after waiting a few minutes. I was now getting:
[FormatException: Input string was not in a correct format.] System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +7469351 System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +119 System.Convert.ToInt32(String value, IFormatProvider provider) +48 Microsoft.SharePoint.WebControls.ItemHiddenVersion.OnLoad(EventArgs e) +293 System.Web.UI.Control.LoadRecursive() +50 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Control.LoadRecursive() +141 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627
So I started digging around in reflector to see what was going on in that control:
// Methods [SharePointPermission(SecurityAction.Demand, ObjectModel=true)] protected override void OnLoad(EventArgs e) { this.EnsureChildControls(); base.OnLoad(e); if ((((base.ControlMode == SPControlMode.Edit) && (base.ListItem != null)) && this.Page.IsPostBack) && !base.InDesign) { HtmlInputHidden hidden = (HtmlInputHidden) this.TemplateContainer.FindControl("owshiddenversion"); if (hidden == null) { throw new ArgumentException("Corrupted ItemHiddenVersion template."); } base.ListItem["owshiddenversion"] = hidden.Value; Convert.ToInt32(hidden.Value, CultureInfo.InvariantCulture); } }
I guess the hidden.Value or owshiddenversion is empty or some sort of string. Now Microsoft actually has an article on this owshiddenversion property [4] where they state:
“Windows SharePoint Services 3.0 uses the owshiddenversion Field (in the Microsoft.SharePoint.SPBuiltInFieldId Class) to detect conflicts. If this field value is not supplied during the update process, the server will overwrite all changes. A client must always supply this field value during the update process, in order to prevent data loss. The field value is the number that the server returned most recently.”
I guess what might be happening is that the page is in some sort of conflict state. I’m going to try and remove the ItemHiddenVersion SharePoint control that was put in from the hotfix [2] to see what happens next.
I removed it (line below) and things seem to be working, let's wait and see.
<SharePoint:ItemHiddenVersion runat="server" ControlMode="Edit"/>
[1] http://kalsing.blogspot.com/2006/11/create-custom-list-form-for-sharepoint.html
[2] http://support.microsoft.com/default.aspx/kb/953271
[3] http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/ed33bbd4-a396-476e-b04e-88161dfbdac6/
[4] http://msdn.microsoft.com/en-us/library/cc264293.aspx