Home Page Link
  Skip Navigation Links
SharePoint, Development
October 01
Visual Studio Web Part Templates
You create a new web part project with the SharePoint template.  Start coding, rename some stuff, build, deploy.  Then get
"The feature name WebParts already exists in SharePoint. You need to rename the feature before solution deployment can succeed"
 
 
What I did to fix this is to open the project folders in explorer, find the pkg folder and rename it.  New feature.xml's and so on will be created.
 
 
October 01
SPUrl to make relative Urls in SharePoint Markup
SPUrl is a handy command you can put into any SharePoint markup.
 
Say your master page needs to show a relative url, remember the master page can appear on any number of sub webs, so url relativity is, well, relative .
You could use ../../../../../N, buts thats inelegant.
 
The only catches are the runat="server" tag and the id="footer-content" tag.  SPUrl is done server side, another reason its better than javascript.
 
 
e.g. <td id="footer-content" >Best viewed at 1024x768 resolution using IE 6 or later.
<a id="A1" runat="server" 
                                                        href="<% $SPUrl:~SiteCollection/Pages/UserAgreement.aspx %>">User Agreement</a>
</td>
October 01
stsadm character encoding
Ever had a command line in stadm that kept giving an error about syntax? Even though you checked it a hundred times?
 
Well I have, and seems to be charcter encoding. 
 
I tend to save all my cmd commands in a text file.  I fixed the encoding by making notepad use the correct encoding.
 
 
October 01
Find Object in Generic List
IMHO anonymous code is not good.  But it has its uses...
 
Trying to find an object in a generic list is a pain, you will need to implement interfaces and generally write complex hard to read code.
 
Now anonymous code goes against readability, usually.  In this cases it increases it.  I trade a bit of structure and labeling for a delegate, vis:
 
List<>.Find(delegate(List<> o) { return o.Property == SearchString; }); 
            }

In context
            List<MOSSURLAndEmailStringArray> mossURLAndEmailList = new List<MOSSURLAndEmailStringArray>();
            mossURLAndEmailList = GetAllMOSSListUrlsAndEmails();
            foreach (string adContactEmail in activeDirectoryResults)
            {
                MOSSURLAndEmailStringArray mossURLAndEmailStringArray = mossURLAndEmailList.Find(delegate(MOSSURLAndEmailStringArray o) { return o.MOSSEmail == adContactEmail; }); 
            }
June 23
Programmatically Edit Content Editor Web Part
 
Say you are migrating sites, o nthe landing page you have a CEWP.  Inside the content are links, it was not possible to make them relative.
 
The code finds the default page, open it, get the web part.  loads the web part content, changes it and saves changes.
 
  private static void UpdateCEWPForlandingPageIPLinks(SPWeb updateWebPartWed)
  {
   SPFile file = updateWebPartWed.GetFile("default.aspx");
   SPLimitedWebPartManager webPartManager = file.GetLimitedWebPartManager(PersonalizationScope.Shared);
   SPLimitedWebPartCollection webParts = webPartManager.WebParts;
   foreach (Microsoft.SharePoint.WebPartPages.WebPart webPart in webParts)
   {
    if (((object)webPart).GetType().ToString() == "Microsoft.SharePoint.WebPartPages.ContentEditorWebPart")
    {
     if (webPart.Title == "New BCM Form")
     {
      string newIPURL = "";
      ContentEditorWebPart contentEditorWebPartWorking = new ContentEditorWebPart();
      // Create an XmlElement to hold the value of the Content property.
      XmlDocument xmlDocument = new XmlDocument();
      XmlElement xmlElement = xmlDocument.CreateElement("Content");
      xmlElement.InnerText = ((ContentEditorWebPart)webPart).Content.InnerText.ToString();
      //BIRA
      newIPURL = GetNewBCMLinksList(updateWebPartWed.Site.Url, updateWebPartWed.ServerRelativeUrl, "BIRA");
      xmlElement.InnerText = xmlElement.InnerText.ToString().Replace("BIRAurl", newIPURL);
      //BCS
      newIPURL = GetNewBCMLinksList(updateWebPartWed.Site.Url, updateWebPartWed.ServerRelativeUrl, "BCS");
      xmlElement.InnerText = xmlElement.InnerText.ToString().Replace("BCSurl", newIPURL);
      //BCP
      newIPURL = GetNewBCMLinksList(updateWebPartWed.Site.Url, updateWebPartWed.ServerRelativeUrl, "BCP");
      xmlElement.InnerText = xmlElement.InnerText.ToString().Replace("BCPurl", newIPURL);
      //BCIT
      newIPURL = GetNewBCMLinksList(updateWebPartWed.Site.Url, updateWebPartWed.ServerRelativeUrl, "BCIT");
      xmlElement.InnerText = xmlElement.InnerText.ToString().Replace("BCITurl", newIPURL);
      //BCT
      newIPURL = GetNewBCMLinksList(updateWebPartWed.Site.Url, updateWebPartWed.ServerRelativeUrl, "BCT");
      xmlElement.InnerText = xmlElement.InnerText.ToString().Replace("BCTurl", newIPURL);
      contentEditorWebPartWorking.Content = xmlElement;
      ((ContentEditorWebPart)webPart).Content = contentEditorWebPartWorking.Content;
      updateWebPartWed.AllowUnsafeUpdates = true;
      webPartManager.SaveChanges(webPart);
      file.Update();
      updateWebPartWed.Update();
      updateWebPartWed.AllowUnsafeUpdates = false;
     }
    }
   }
  }
 
June 23
Browser Enabled Infopath Forms Error
 
Users will intermittantly get this error:

"There has been an error while loading the form.  A required resource could not be downloaded.  To try to resume the download, refresh the page"
 
Check the hosts files all the servers in the farm.
 
C:\Windows\System32\drivers\etc\hosts
 
 
 
 
June 23
InfoPath: Reading Repeating Tables from SharePoint List
Lets say you have an Infopath form that submits to a list.
Seems easy enough, lets say that IP form has many repeating tables (IP is not up to massive forms).
 
Then you will have a problem.  Seems like the data gets saved in some arcane schema, even using the lists property bags for stuff (crazy!)
 
After some serious poking around (I could not decrypt the schema),  I discovered that the data is a serialized IP form.
 
This took several days to discover and peice together people
 
 
   using (SPSite site = new SPSite("http://moss:777"))
   {
    using (SPWeb web = site.OpenWeb("BCM"))
    {
     SPList list = web.Lists["BCS Forms"];
     SPFolder folder = web.GetFolder("BCS Forms");
     SPFile file = folder.Files[17];
     Byte[] byteBuffer = file.OpenBinary();
     MemoryStream xmlStream = new MemoryStream(byteBuffer);
     XmlDocument xsd = new XmlDocument();
     XmlSerializer serializer = new XmlSerializer(typeof(XmlDocument));
     xsd = (XmlDocument)serializer.Deserialize(xmlStream);
    }
   }
 
June 23
InfoPath: Binding a Web Service to a Repeating Table
Clients love Rich Text Fields.
 
But how do you get a custom .net web service node to bind to a RTF in a repeating group?
 
 
found some hints:
 
then I found through trial and error
that if I added an XHTML node it would work.  Talk about hacking.
 
for example:
XmlElement theFontNode = (XmlElement)tempDocument.CreateNode(XmlNodeType.Element, "font", "http://www.w3.org/1999/xhtml");
 
 
 
 
June 23
When not to use Infopath
 
Pre-sales loves the idea that they can sell IP (InfoPath).  Telling clients that the end users will be able to maintain the applications.
 
In many cases this is correct.
 
However:
1)  If its so easy then why are the end users doing the forms?
1)  Motivation.  Devs don't want to do IP, its not cool
2)  There is some learning involved
 
What happens to code?
 
Famous software engineer Brooks wrote a paper called "No Silver Bullet"
http://en.wikipedia.org/wiki/No_Silver_Bullet
The paper says, inter alia, it will be used in ways that are not intended.
 
Well written software gets used for more than intended.  If the devs start doing Infopath Forms, the forms will inevitably get used for unscalable applications
If we as devs must write systems that use software designed for end users it creates some problems:
1) Parts of it will be in complicated .net code (end users can forget fixing code behind)
2) Unmaintainable, 50 IP forms all calling one another, IP rules, work arounds etc?
3) IP does not scale in the way devs expect
 
 
My rule:
1) Make the end users do it
2) If it would take longer that 2 hours, then code it with the enterprise scale stuff, like asp.net
3) If there are going to be lots of IP forms
4) ANY code behind
 
 
 
June 23
Error Deploying Web Service
Whilst deploying a .net web service that was to be called by InfoPath browser enabled forms I got a wierd error vis:
 
"The Web Application at could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."
After googling a bit I changed the changede the WS to be on same app pool as Portal.
 
Viola problem solved
 
 
 
 
 
 
 
 
1 - 10Next

Feedback