Aug 24

Here's a useful post on how to map a SharePoint URL with PictureURL in user profile properties.

http://spmat.blogspot.com/2010/10/how-to-map-sharepoint-2010-pictureurl.html

Here's one to map an extension attribute in AD to the PictureURL in user profile properties.

http://goodbadtechnology.blogspot.com/2010/05/setting-up-pictureurl-user-profile.html

Unfortunately, as you can see from these examples, it's not exactly a straightforward task.

Jul 28
Editing InfoPath 2010 xml with C#
Posted by Wei in C#, InfoPath, SharePoint on 07 28th, 2011| | No Comments »

Here's a code snippet to edit nodes in an existing InfoPath 2010 Xml document from a selected Form Library in SharePoint 2010:

 SPWeb mySite = SPContext.Current.Web;
 SPList oList = mySite.Lists["FormLibraryName"];
 SPQuery oQuery = new SPQuery();
 oQuery.Query = "<Where><Eq><FieldRef Name='FileLeafRef'/><Value Type='Text'>TargetFile.xml</Value></Eq></Where>";
 SPListItemCollection listItems = oList.GetItems(oQuery);

 if (listItems.Count > 0)
 {
  SPListItem item = listItems[0];

  MemoryStream oMemoryStream = new MemoryStream(item.File.OpenBinary());
  XmlTextReader oReader = new XmlTextReader(oMemoryStream);

  XmlDocument oDoc = new XmlDocument();
  oDoc.Load(oReader);

  oReader.Close();
  oMemoryStream.Close();

  XmlNamespaceManager nameSpaceManager = new XmlNamespaceManager(oDoc.NameTable);
  nameSpaceManager.AddNamespace("my", oDoc.DocumentElement.NamespaceURI);

  oDoc.DocumentElement.SelectSingleNode("my:NodeToUpdate", nameSpaceManager).InnerText = "Update text";
  oDoc.DocumentElement.SelectSingleNode("my:Node/my:SubNode", nameSpaceManager).InnerText = "Update text";

  mySite.AllowUnsafeUpdates = true;

  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
  SPFile oSPFile = mySite.Folders[mwp.FormLibraryName].Files.Add(item.File.Name, (encoding.GetBytes(oDoc.OuterXml)), true);
 }

May 2
Uploading large files in SP 2010 IIS7
Posted by Wei in IIS on 05 2nd, 2011| | No Comments »

To be able to upload files greater than 28Mb (even after setting the Maximum Upload Size in SP 2010 Central Admin to 100Mb), we need to go into IIS. By default IIS limits uploaded files to 28Mb so to increase the limit, we need to add the following into web.config

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="2147483647" />
        </requestFiltering>
    </security>
</system.webServer> 

Place that under the </system.web> tag

Apr 20

Add a content editor web part to the document library page. On the content editor web part, add the following javascript. Be sure to modify the value for strAction to what you need. In this case, it is set to redirect to SomePage.aspx with the ListID and ItemID Parameters.

<script type="text/javascript">
function Custom_AddDocLibMenuItems(m, ctx) {
 var strDisplayText = "Edit Item Metadata";
 var strAction = "window.location.href='../../Pages/SomePage.aspx?ListID=" + ctx.listName.substr(1, 36) + "&ItemID=" + currentItemID + "';";
 var strImagePath = "/_layouts/images/edititem.gif";
 CAMOpt(m, strDisplayText, strAction, strImagePath);
 CAMSep(m);
 return false;
}</script>

Apr 12

I've always wondered why SP 2010 document libraries has an Add Document but not a New Document link on their document libraries. Probably because they don't expect users to click on New Document very often and only expect users to Add Documents (upload documents from their PC to the document library).

Anyway, the client has these custom word templates and they require users to use these word templates when creating new documents. This means their process requires users to click on New Document everytime they want to place something in the document library. So to make things easier for them, I have added a Content Editor web part and added code to it that would allow users to click the link to create the document based off the template.

<IMG alt="" src="/_layouts/images/rect.gif">&nbsp;<a href="#" onclick="createNewDocumentWithProgID('http:\u002f\u002fintranet\u002fDocument Library\u002fForms\u002fDocument Template.dotx', 'http:\u002f\u002fintranet\u002fDocument Library', 'SharePoint.OpenDocuments', false)">New Document</a>

&nbsp;&nbsp;&nbsp;

<span style="height:10px;width:10px;position:relative;display:inline-block;overflow:hidden;"><img src="/_layouts/images/fgimg.png" alt="" style="left:-0px !important;top:-128px !important;position:absolute;" /></span>&nbsp;<a id="idHomePageNewDocument" href="http://intranet/_layouts/Upload.aspx?List={DocLibGUID}&amp;RootFolder=" onclick="javascript:NewItem2(event, &quot;http://intranet/_layouts/Upload.aspx?List={DocLibGUID}&amp;RootFolder=&quot;);javascript:return false;" target="_self">Add document</a>

Don't forget to edit the DocLibGUID with the GUID to the document library in order for the Add document link to work. Remember to also check the path to the document libraries and templates.

Using the same method, we can replicate everything in the ribbon on the site itself. This way, the client has an option to hide the ribbon and have more control over what options are available to different groups of users.

« Previous Entries Next Entries »