Archive for the ‘Sharepoint’ Category
Posted by mundeep on May 22, 2009
A common tasks developers are required to do with Sharepoint is migrated documents from either legacy systems or older Sharepoint sites into a document library. There are many ways to do this documented out there (most commonly using the Files.Add method of the API), but one of the common requirements during this ‘migration’ is to retain the Created Date or Created By fields. Sowmyan’s blog has a good description of how to set the Created By/Modified By user fields here.
Updating the Created Date of a document or list item in Sharepoint is even easier, simply set the “Created” field of the item to the value you wish to set. For example if using the Files.Add methods in the API (as described by Dave Hunter) then the following code snippet will update the Created Date:
// add the file
SPFile file = docLib.RootFolder.Files.Add(newFileName, inputStream);
// get the list item for that file
SPItem item = file.Item;
//Set the Created Date
item["Created"] = "2009-02-26 15:00:00";
item.Update();
Posted in .NET, Sharepoint | Tagged: .NET, c#, Sharepoint, WSS | Leave a Comment »
Posted by mundeep on February 24, 2009
Ran into a colleague’s code that was incorrectly trying to check if a folder existed. It was something like:
private bool CheckFolderExists(SPWeb parentWeb, string folderName) {
SPFolder folder = parentWeb.GetFolder(folderName);
if (folder == null) {
return false;
}
else {
return true;
}
}
however this always returns an actual SPFolder object, and the correct way is to check the Exists property of the returned object ie:
private bool CheckFolderExists(SPWeb parentWeb, string folderName) {
SPFolder folder = parentWeb.GetFolder(folderName);
return folder.Exists;
}
NB: Yes, this post is almost identical to my earlier one about checking if an SPWeb object exists.
Posted in .NET, Sharepoint | Tagged: c#, Sharepoint, SPFolder | 2 Comments »
Posted by mundeep on February 17, 2009
While trying to deploy an InfoPath Form to sharepoint via stsadm commands i received the error:
InfoPath Forms Services is not turned on.
Initially thinking that the Enterprise features where not enabled in the Site Collection i was deploying to i tried activating the “Office SharePoint Server Enterprise Site Collection features”, however that did not make a difference.
Turns out the problem was that the account i was trying to deploy under (my own) did not have sufficient permissions (to what i am not sure – but i am guessing the configuration database), running the deployment under an account with more priveleges solved the problem.
Summary: If you get the above error make sure to try your deployment/stsadm commands under an account with higher priveleges (most likely access to the config database).
Posted in Sharepoint | Tagged: Config Database, Forms Services, InfoPath, Sharepoint | Leave a Comment »
Posted by mundeep on February 16, 2009
I was recently trying to converting some InfoPath froms that had been created as per default in the InfoPath client application (and using Visual Studio Tools for Applications for Code-Behind) into a Visual Studio project to be opened in Visual Stdio 2005 as per the MSDN HowTo. However when i reached the last step and opened the masnifest.xsf it would just me show me the xml contents of the file and not the visual form editing GUI that you see in the InfoPath client. Solution was to install Visual Studio 2005 Tools for Office Second Edition (VSTO 2005 SE) and then reopen the project.
Posted in .NET, Sharepoint | Tagged: InfoPath, manifest.xsf, visual studio, visual studio tools for applications, visual studio tools for office | Leave a Comment »
Posted by mundeep on February 12, 2009
While developing a Sharepoint solution using WSPBuilder and Visual Studio 2005 i noticed that i would get the following error when trying to compile a Release build (on further examination i noticed that it would occur whenever i switched between release & debug builds):
“sgen.exe exited with code 1″
After doing some research i found a several different suggested solutions:
- Remove and re-add the project from the solution as per this forum post.
- Turn off the “Generate serialization assembly” option in the Build tab of Project Properties see this blogpost and this one.
- Remove the previous version of the assembly from the GAC as per this blogpost.
To determine which solution i should use required some more research on sgen.exe does. As per the MSDN article:
When the XML Serializer Generator is not used, a XmlSerializer generates serialization code and a serialization assembly for each type every time an application is run. To improve the performance of XML serialization startup, use the Sgen.exe tool to generate those assemblies the assemblies in advance. These assemblies can then be deployed with the application.
The XML Serializer Generator can also improve the performance of clients that use XML Web service proxies to communicate with servers because the serialization process will not incur a performance hit when the type is loaded the first time.
These generated assemblies cannot be used on the server side of a Web service. This tool is only for Web service clients and manual serialization scenarios.
If the assembly containing the type to serialize is named MyType.dll, then the associated serialization assembly will be named MyType.XmlSerializers.dll.
This means that as well as being impractical the first solution doesn’t really solve the problem.
The second solution ’solves’ the probelm, however based on the MSDN article it may result in a minor performance hit if the serialization class is required.
In my case i was performing some manual serialization and thus decided to live with the minor annoyance of soltuion #3 and removing the existing assemblies from the GAC whenever i ran into the error.
Posted in .NET, Sharepoint | Tagged: compiling, serlialization, sgen.exe, visual studio, xml | Leave a Comment »
Posted by mundeep on October 21, 2008
Ran into problems in a virtualised (vmware) sharepoint environment where stsadm commands would take a long time to run (upto 30 seconds for a simple stsadm -?) when running under my account but it would run fine (couple of seconds) under a different user account.
After scratching our heads and trying to determine if any security groups where missing from my account (and the other people this would happen to) we narrowed it down to occuring only on machines where we did not perform the sharepoint install.
This didn’t really help solve the problem but some googling bought me to Mark Rhode’s blog where he explains that the problem is usually due to stsadm trying to query crl.microsoft.com before executing – hence our issue being that internet proxies where not correctly setup for some users.
The simplest solution to the problem is to correct the proxy so the environment has internet access. However for those that don’t want to (or can’t) open their virtual environments to the internet, Mark has a couple of other suggestions (such as adding a host entry for crl.microsoft.com pointed to 127.0.0.1). Paul Horsfall also explains how he found the problem using Ethereal and then used proxycfg.exe to setup his proxy.
Posted in Sharepoint | Tagged: proxy, Sharepoint, stsadm | Leave a Comment »
Posted by mundeep on September 9, 2008
While working with Sharepoint User Profiles I have had to perform a hack to remove Mapped property images or Warning property images from the Sharepoint User Profiles edit page. Using the default ShowMappedIcon or ShowWarningIcon properties of the “UserProfileEditor” control easily allow you to hide the warnings and mapping information however it destroys the layout of the rest of the editing page by missing lots of table cells and results in an ugly looking page.
As a result i had to instead leave ShowMappedIcon=”true” and then use the following javascript to hide all the mapping images and wording:
/// <summary>
/// Hide mapping text and images.
/// </summary>
function clearMappingDisplay() {
try {
//Hide Mapping Images
//Find all images on page
var images = document.getElementsByTagName('IMG');
for (var i=0; i < images.length; i++) {
var curImage = images[i];
//If image is for "Mapped" property
if(curImage.alt == "Mapped") {
//Replace image with blank.gif & hide image
curImage.src = curImage.src.replace("mapped", "blank");
curImage.style.visibility = "hidden";
}
}
//Hide mapping text
//Get tblMain container
var mainTable = document.getElementById('tblMain');
//Get all tables within main table
var subTables = mainTable.getElementsByTagName('TABLE');
for (var i=0; i < subTables.length; i++) {
var curTable = subTables[i];
//Find the table that includes the mapping text
if(curTable.innerText.indexOf("mapped for profile import") > -1) {
for (var k=0; k < curTable.cells.length; k++) {
var cell = curTable.cells[k];
//Find the cell that contains the mapping text
if(cell.innerText.indexOf("mapped for profile import") > -1) {
//Clear the mapping text
cell.innerText = "";
}
}
}
}
}
catch (ex) {
//TODO: Handle error.
}
}
//Ensure sharepoint runs the clearMappingDisplay method on Page (Body) Load
_spBodyOnLoadFunctionNames.push("clearMappingDisplay");
Posted in Sharepoint | Tagged: Javascript, Sharepoint | Leave a Comment »
Posted by mundeep on August 20, 2008
My colleague Ishai Sagi recently did some research into what accounts the people picker shows and determined the LDAP query that was being used to display accounts if you are using Windows authentication. I did some further research into this and i have noticed that aswell as your authentication provider source (eg. LDAP accounts for sites using Windows Authentication/Active Directory) the picker also shows accounts from the User Information List.
This is important to note as it means that accounts that may have been deleted or disabled in your authentication provider still come up to be selected by users that are entering information into a people field.
For further details on the User Information List see this article on Andrew Connell’s blog which appears to be for Sharepoint 2003 however seems to still mostly apply for MOSS. Also Sahil Malik has done some research into User Profile Information and how it flows.
Posted in Sharepoint | Tagged: Active Directory, MOSS, Sharepoint, User Information List, WSS | Leave a Comment »
Posted by mundeep on August 14, 2008
I was debugging a problem today where i would get the following error recently when trying to associate a content type with a document library:
Value does not fall within the expected range. at Microsoft.SharePoint.SPFileCollection.get_Item(String urlOfFile)
at Microsoft.SharePoint.SPContentTypeCollection.Add(SPContentType contentType)
at Microsoft.SharePoint.ApplicationPages.AddContentTypeToListPage.Update(Object o, EventArgs e)
at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
After examining the elements.xml and confirming that (a) all the bound content types exists and (b) all the site columns used by the content types existed, i noticed that there was a mis-match in the name of the content-type and the url used in the module to deploy the document template. A snippet of the elements.xml specific to one of the content-types is shown below.
<ContentType Name="Briefing (Event)" Group="Custom Document Content Types" Description="" ID="0x0101002DB264DB4656424CB8247FDE6BA03F7E021C">
<FieldRefs>
<FieldRef ID="{52578fc3-1f01-4f4d-b016-94ccbcf428cf}" Name="Comments" />
<FieldRef ID="{cd94be8c-d754-4a6d-865d-7cb40375b11c}" Name="Document Status" />
...
<FieldRef ID="{130da223-b498-417c-9bdd-1fc2ac43aa6e}" Name="Country" />
</FieldRefs>
<DocumentTemplate TargetName="Briefing_template.doc" />
</ContentType>
<Module Name="Briefing" Url="_cts/Briefing" RootWebOnly="true">
<File Url="Briefing_template.doc" Name="Briefing_template.doc" Type="Ghostable" />
</Module>
The mistake was that the Url=”_cts/Briefing” property of the module should have been Url=”_cts/Briefing (Event)” to match the Name of the content-type.
Update: I also ran into the same error on another content type where the name of the template file in the tag did not match the actual filename.
Posted in Sharepoint | Tagged: Content Types, MOSS, Sharepoint | Leave a Comment »
Posted by mundeep on December 19, 2007
Ran into a problem today where we were incorrectly trying to check if a web existed. We were trying:
private bool ChildWebExists(SPWeb parentWeb, string childWebName) {
return null != parentWeb.Webs[childWebName];
}
however this always returns an actual SPWeb object, turns out the correct way is to check the Exists property of the returned object ie:
private bool ChildWebExists(SPWeb parentWeb, string childWebName) {
using (SPweb childWeb = parentWeb.Webs[childWebName]) {
return childWeb.Exists;
}
}
Posted in Sharepoint | Tagged: Sharepoint, spweb | 1 Comment »