Delphi Technology Solutions - development, websites, computers and networks

Development   |   Computers & Networks   |   Websites   |   Products & Services   |   Client Success   |   News

David's Ramblings on Development

SharePoint, InfoPath, .Net and more




How to ask a question

Share |
clock July 10, 2009 11:59 by author David Lozzi

I thought this was funny, so I wanted to share. Microsoft has a knowledge base article explaining how to ask a question!

http://support.microsoft.com/default.aspx/kb/555375

Enjoy!





Versioning Your Published InfoPath Forms

Share |
clock July 8, 2009 11:19 by author David Lozzi

If you haven't experienced it already, when you have an InfoPath form live on your server, and you make a change to the schema of the form and upload it over the existing copy, your old forms won't open. There is a work around we have applied with our customer which works well for us and I'll continue to explain it here.
 
If you are stuck right now, and you already uploaded a new form and lost access to your old forms: find the previous version. Whether from backup or source safe, roll back to when it did work and move that form live. Then follow these steps.
 
Test it out.
In my scenario, I have a test server and a production server. All changes are uploaded over the current forms on the test server to determine if we need to version our forms on the production server. If my memory serves me correctly, ANY changes to the schema will require a versioned copy so the old copy can still be accessed. If you change the style of the form (layout changes, colors, images) this should be fine for a direct upgrade. But test it out. If a test box isn't available, then check out Keeping Your Versions below.
 
Version it.
Unfortunately there is no easy way to version content types other than manually updating the files yourself. For example, we have a form RequestforInformation.xsn.
 
a) We made a schema change so now I publish the form as RequestForInformation_v1.1.xsn. We now upload this into the Form Templates on the server and activate it to our collection.
b) Go to the settings of the form library and add the new content type. You will now have two content types listed.
c) Rename the old content type to it's version, in my example I renamed it to RequestForInformation_v1.0.
d) Rename the new content type by removing the version reference: RequestForInformation.
e) Click "Change new button order and default content type" below the content types list and uncheck Visible for the old content type.
Now in the form library when you click New you will use the new form. When you view an existing record it'll still open in the old form!
 
Keeping your versions.
What happens if you accidently upgraded a form with a new schema change and thus blowing up your existing forms? Like I said in the beginning, you'll need to find a backup somewhere and restore it. Moving forward from here, use SharePoint's resident versioning controls to store all of your published InfoPath forms and finding your backup is a breeze.
 
a) Create a new library somewhere in your SharePoint site and enable versioning.
b) On the computer you are performing your InfoPath development, browse to this library and open it in Windows Explorer. If you are developing on a Windows 2008 server, check out http://insomniacgeek.com/blog/sharepoint-open-with-windows-explorer-on-windows-server-2008/ to enable access to SharePoint's Explorer integration.
c) With it open, map a network drive to the opened folder. I used i: for InfoPath Forms
d) When you publish a form, publish it to your new drive.
e) When you go to upload the form to the server in Central Admin, browse to the new drive and use that copy.
 
So simple isn't it... Now, when you create v1.1 and so on for a form, all of the previous versions will be saved in SharePoint. If you make a schema change and forget to create a manual version, SharePoint versioning will be there to save the day!
 
Hope this helps!!





Using SharePoint properties to save values instead of web.config

Share |
clock July 6, 2009 09:31 by author David Lozzi

A while back I ran into this issue: I had two web parts in the same project but I wanted them to share settings. As my experience as an ASP.Net developer was pointing me to use the web.config file, instead I thought SharePoint must have something similar to this without me having to mess with the web.config file. After searching and posting on MSDN, I did finally find a solution that uses the properties of SharePoint Sites and Webs.

Below is a sample code that stores the Employee Profile Group in the web so two web parts and an InfoPath form can access the values.

The GetWebProperty function creates the property if it doesn't exist, and if it does it'll return the string value. It's important to call this function before setting a web property, especially the first time it's run so the property is created. I suppose you could technically put the same creation functionality in the SetWebProperty as well, but I was using Get (getting values into my webpart) before my Set (using edit pane to view it).

string employeeProfile = GetWebProperty("EmployeeProfileUserGroup");

SetWebProperty("EmployeeProfileUserGroup", pe.DisplayText);

static string GetWebProperty(string Name)
{
 using (SPSite site = new SPSite(SPContext.Current.Site.ID))
 {
  SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);
  if (web.Properties[Name] == null)
  {
   web.AllowUnsafeUpdates = true;
   web.Properties.Add(Name, "");
   web.Properties.Update();
   web.AllowUnsafeUpdates = false;
   return "";
  }
  else
  {
   return web.Properties[Name].ToString();
  }
 }
}
void SetWebProperty(string Name, string Value)
{
 using (SPSite site = new SPSite(SPContext.Current.Site.ID))
 {
  SPWeb web = site.OpenWeb(SPContext.Current.Web.ID);
  GetWebProperty(Name); //ensure the property exists
  web.AllowUnsafeUpdates = true;
  web.Properties[Name] = Value;
  web.Properties.Update();
  web.AllowUnsafeUpdates = false;
 }
}

If you would like to share the same properties across multiple webs, use the Site.RootWeb object and store all properties there!

Enjoy!





Versioned Comments in InfoPath

Share |
clock July 2, 2009 16:57 by author David Lozzi

One great feature of SharePoint and versioning is the ability to have versioned comments. This can allow a small discussion to occur on almost any item. It also allows someone to keep a running log of notes on certain items.

I had the wonderful task of figuring out how to get this to work the same in InfoPath. Below is a function that will append the notes into a repeating group. On submit of the form, I call this function and it works great, everytime!

public void AddAnalystNotes()
{
 try
 { //this is the text box the user enters their notes into.
  if (GetNodeValue(GetRootNodeName() + "/my:DetailsSection/my:AddAnalystNotes/my:AddNotes") != "")
  { //this is the group in the datasource just above the repeating group
   XPathNavigator selReqs = MainDataSource.CreateNavigator().SelectSingleNode(
   GetRootNodeName() + "/my:DetailsSection/my:AnalystNotesGroup", NamespaceManager);
   
   string nsPrefix = selReqs.Prefix;
   string nsURI = selReqs.NamespaceURI;
   
   //this is the repeating group of notes
   XPathNodeIterator selAnalyst = MainDataSource.CreateNavigator().Select(
   GetRootNodeName() + "/my:DetailsSection/my:AnalystNotesGroup/my:AnalystNotes", NamespaceManager);
   
   XmlWriter writer;
   //if there are already items in the list, pop this new note at the top
   if(selAnalyst.Count > 0){
    selReqs.MoveToChild("AnalystNotes",nsURI);
    writer = selReqs.InsertBefore();
   }else{
    writer = selReqs.AppendChild();
   }
   
   //now write the values
   writer.WriteStartElement(nsPrefix, "AnalystNotes", nsURI);
   writer.WriteElementString(nsPrefix, "CreatedDate", nsURI, DateTime.Now.ToString());
   writer.WriteElementString(nsPrefix, "CreatedBy", nsURI, SPContext.Current.Web.CurrentUser.Name);
   writer.WriteElementString(nsPrefix, "Notes", nsURI, ""); //have to create a blank entry then add the value later down the line
   writer.WriteEndElement();
   writer.Close();
   
   //gets the text box with the new notes in it
   XPathNavigator xnotes = MainDataSource.CreateNavigator().SelectSingleNode(
   GetRootNodeName() + "/my:DetailsSection/my:AddAnalystNotes/my:AddNotes",NamespaceManager);
   
   selAnalyst.MoveNext(); //grab the first element, the default is root
   
   //had to use InnerXml, the value to value loses HTML formatting
   selAnalyst.Current.SelectSingleNode("my:Notes",NamespaceManager).InnerXml = xnotes.InnerXml;

   //clears the text box
   SetNodeValue(GetRootNodeName() + "/my:DetailsSection/my:AddAnalystNotes/my:AddNotes", "");
  }
 }
 catch (Exception ex)
 {
  WriteErrorToLog("addRequestor_Click", "Adding analyst noteserrored", ex);
 }
}

Then in the view, format the repeating group to be read-only and blamo, versioned comments.

 




RSSRSS Subscribe

About David Lozzi

I love what I do. I'm not the sketchy type that hides in his basement coding all day. I have a beautiful wife and two great children. I've spent my last 10 years plus in the technology arena. more...

Login