Search


Monday, December 22, 2008

Query String passing in Infopath C# code

   1: public void FormEvents_Loading(object sender, LoadingEventArgs e) 
   2: { 
   3:     string lotNumber = string.Empty; 
   4:     try 
   5:     { 
   6:         e.InputParameters.TryGetValue("LotNumber", out lotNumber); 
   7:     } 
   8:     catch (Exception ex) 
   9:     { 
  10:         lotNumber = ex.Message.ToString();
  11:     } 
  12:     finally 
  13:     { 
  14:         MainDataSource.CreateNavigator().SelectSingleNode("//my:LotNumber", NamespaceManager).SetValue(lotNumber); 
  15:     } 
  16: }

Tuesday, December 16, 2008

IIS problem XML parsing

Problem:

The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. A name was started with an invalid character. Error processing resource

Line 1... <%@ Page Language="vb" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.Framework.DefaultPage" CodeFile="Defa... Line 1...<%%@ Page Language="C#" AutoEventWireup="false" Explicit="True" Inherits="DotNetNuke.Framework.DefaultPage" CodeFile="Defa... Solution: this basicly happens when IIS installed after .Net frame work. to fix this. Go to IIS manager : start -> run -> inetmgr go to your application root properties go to ASP tab make sure ASP version is not blank ( 2.0) now repair ASP.net frame work by going to control panel and change/repair.

Node manipulation using Xpath C# infopath code

   1: private string GetNodeValueFromMain(string xpath) 
   2: { 
   3:     string retValue = string.Empty; 
   4:     XPathNavigator retNode = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager); 
   5:     if (retNode != null) 
   6:     { 
   7:         retValue = retNode.InnerXml; 
   8:     } 
   9:     return retValue; 
  10: } 

Occasionally, the node value that you are retrieving is relative to a particular event object site (for example, a sibling node in a Changed event). In the GetNodeValueFromEvent function, the event object is passed as an argument along with the XPath statement.

   1: private string GetNodeValueFromEvent(XmlEventArgs eventObject, string xpath) 
   2: { 
   3:     string retValue = string.Empty; XPathNavigator retNode = eventObject.Site.SelectSingleNode(xpath, NamespaceManager); 
   4:     if (retNode != null) 
   5:     { 
   6:         retValue = retNode.InnerXml; 
   7:     } 
   8:     return retValue; 
   9: } 

To retrieve a node value from a secondary data source, you must pass the name of the data connection as
an argument, along with the XPath statement, as shown with the GetNodeValueFromSecondary function.

   1: private string GetNodeValueFromSecondary(string source, string xpath) 
   2: { 
   3:     string retValue = string.Empty; XPathNavigator retNode = DataSources[source].CreateNavigator().SelectSingleNode(xpath, NamespaceManager); 
   4:     if (retNode != null) 
   5:     { 
   6:         retValue = retNode.InnerXml; 
   7:     } 
   8:     return retValue; 
   9: } 

Setting a Node Value Another task used in most managed-code solutions is setting a particular node value in the main data source. The SetNodeValueInMain function uses the first XPath statement argument to identify an XPathNavigator object and then set it to the value of the second argument.

   1: private void SetNodeValueInMain(string xpath, string nodeValue) 
   2: { 
   3:     XPathNavigator mainNode = MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager); 
   4:     if (mainNode != null) 
   5:     { 
   6:         mainNode.SetValue(nodeValue); 
   7:     } 
   8: } 

As with retrieving values, there are occasions where you might want to set a node value relative to a particular event object. Note that during certain events (for example, the Changing event), the main data source is read-only. In any
event, the SetNodeValueInEvent function uses an event object as an additional argument.

   1: private void SetNodeValueInEvent(XmlEventArgs eventObject, string xpath, string nodeValue) 
   2: { 
   3:     XPathNavigator eventNode = eventObject.Site.SelectSingleNode(xpath, NamespaceManager); 
   4:     if (eventNode != null) 
   5:     { 
   6:         eventNode.SetValue(nodeValue); 
   7:     } 
   8: } 

To set a secondary data source node value, you must pass the name of the data connection as an argument, along with the XPath statement and new node value, as shown with the SetNodeValueInSecondary function.

   1: private void SetNodeValueInSecondary(string source, string xpath, string nodeValue) 
   2: { 
   3:     XPathNavigator secondaryNode = DataSources[source].CreateNavigator().SelectSingleNode(xpath, NamespaceManager); 
   4:     if (secondaryNode != null) 
   5:     { 
   6:         secondaryNode.SetValue(nodeValue); 
   7:     } 
   8: }

Creating a Node Many times, a repeating section or repeating table control in a form
template has items added to it programmatically during the Loading event or based on specific actions at run time. The CreateNode function takes the first XPathNavigator object argument and appends the node identified by the other three arguments.

   1: private void CreateNode(XPathNavigator parentNode, string childNode, string childNodePrefix, string childNodeValue) 
   2: { 
   3:     if (parentNode != null) 
   4:     { 
   5:         parentNode.AppendChildElement(childNodePrefix, childNode, parentNode.LookupNamespace(parentNode.Prefix), childNodeValue); 
   6:     } 
   7: } 


Removing Nodes Whereas creating a node and adding it to a repeating section or repeating table is a common task, so too is removing a node from one of these repeating controls. The RemoveNode function takes the first XPathNavigator object argument and removes the child node identified with the second XPath
statement argument.

   1:  
   2: private void RemoveNode(XPathNavigator parentNode, string xpath) 
   3: { 
   4:     if (parentNode != null) 
   5:     {
   6:         XPathNavigator childNode = parentNode.CreateNavigator().SelectSingleNode(xpath, NamespaceManager); 
   7:         if (childNode != null) 
   8:         {
   9:             childNode.DeleteSelf(); 
  10:         } 
  11:     } 
  12: } 

 

Removing all items from a repeating section or repeating table involves a reverse iteration through
an XPathNodeIterator object. Here, the RemoveChildNodes function takes the XPathNavigator object and removes all of its child nodes.

   1: private void RemoveChildNodes(XPathNavigator parentNode) 
   2: { 
   3:     if (parentNode != null) 
   4:     { 
   5:         XPathNodeIterator childNodes = parentNode.CreateNavigator().Select("*", NamespaceManager); 
   6:         for (int i = childNodes.Count - 1; i >= 0; i--) 
   7:         { 
   8:             XPathNavigator childNode = parentNode.CreateNavigator().SelectSingleNode("*[last()]", NamespaceManager); 
   9:             childNode.DeleteSelf(); 
  10:         } 
  11:     } 
  12: }

Get Date Year Infopath C# code method

//You could use the substring method on a date string value

//to identify the year, month, or day values.

//In managed code, an easier way is to use the corresponding properties,

//as shown in the GetDateYear function.

private string GetDateYear(DateTime date)

{

string retValue = string.Empty;

retValue = date.Year.ToString();

return retValue;

}

Calculating a Duration in Infopath C# code

//Calculating a Duration

//In some scenarios, it might be a requirement to calculate

//the total number of days in a given period.

//For example, in an expense report solution,

//you might need to identify the duration of the reporting period based

//on a start date and end date. In the GetDuration function,

//two date string values are passed as arguments to retrieve a duration string value.

private string GetDuration(string startDate, string endDate)

{

string retValue = string.Empty;

if (startDate != string.Empty && endDate != string.Empty)

{

long longStartDate = DateTime.Parse(startDate).ToFileTimeUtc();

long longEndDate = DateTime.Parse(endDate).ToFileTimeUtc();

long longDayCount = (longEndDate - longStartDate) / 864000000000 + 1;

retValue = longDayCount.ToString();

}

return retValue;

}

Calculating a Duration in InfoPath

   1: //Calculating a Duration 
   2: //In some scenarios, it might be a requirement to calculate 
   3: //the total number of days in a given period. 
   4: //For example, in an expense report solution, 
   5: //you might need to identify the duration of the reporting period based 
   6: //on a start date and end date. In the GetDuration function, 
   7: //two date string values are passed as arguments to retrieve a duration string value. 
   8: private string GetDuration(string startDate, string endDate) 
   9: { 
  10:     string retValue = string.Empty; 
  11:     if (startDate != string.Empty && endDate != string.Empty) 
  12:     { 
  13:         long longStartDate = DateTime.Parse(startDate).ToFileTimeUtc(); 
  14:         long longEndDate = DateTime.Parse(endDate).ToFileTimeUtc(); 
  15:         long longDayCount = (longEndDate - longStartDate) / 864000000000 + 1; 
  16:         retValue = longDayCount.ToString(); 
  17:     } 
  18:     return retValue; 
  19: }

How to Deploy an InfoPath 2007 Form Containing Managed Code to a Browser-Enabled WSS v3 Library

InfoPath Forms Services is NOT part of WSS v3. It is a separate install, or you can install it as part of the MOSS 2007 Beta 2 install. The RTM version, last I heard, will be available as a separate SKU or as part of MOSS 2007 Enterprise Edition. Assuming you have already created an InfoPath form containing managed code, this document will explain the steps necessary to deploy it to a WSS form library that is “web-enabled” by InfoPath Forms Services. Publish the Template to the File System (or file share) Note: In Office 2007 you can’t publish an InfoPath form containing managed code directly to a WSS form library because it has to be first approved by a WSS Administrator. 1. Open the Design Tasks task pane and choose Publish Form Template. 2. Choose the first option, to publish to SharePoint, and click Next. 3. Enter the location of the SharePoint site you want to publish to. 4. You will be presented with the screen below. Make sure the checkbox is checked to enable the form to be filled out in a browser and click Next. 5. You must choose a location to save the template file, which will be uploaded to the SharePoint site by the site administrator. 6. Specify any columns you want to be made available as WSS columns in the form library. 7. Verify that the information is correct and click Publish. The form will be published to the specified file share location. Upload the Template to the Central Administration Form Templates Library 1. Go to the Central Administration site for your farm (or web server if there's only one) 2. Click on the Application Management tab, go down to the InfoPath Forms Services section, and choose Manage Form Templates. 3. The Form Template library is opened, which is where admin-approved form templates for the farm are stored. 4. Click Upload Form Template. Choose your saved template file and click the Verify button. You will be shown any errors or warnings related to your template file. Read any warnings (hopefully there are no errors) and click OK. 5. Choose your template file again (Why is it not persisted in the text box between postbacks??). In the Upgrade section, you can choose to upgrade the form template if it already exists. You can also choose how to handle current sessions that are using the form template. 6. Click the Upload button to upload the form template. It is now available as a Feature to be activated on any site collections in the farm. Activate the Form Template on a Site Collection 1. You can activate a form template feature from the Manage Form Templates page of Central Administration (the same page where you uploaded the template). On the context menu of the newly uploaded form template, choose Activate to a Site Collection. 2. In the Activation Location section of the page, choose the appropriate Site Collection and click the OK button. Note: You may actually have to change Web Applications to find the site collection you are looking for. A Web Application maps to an IIS virtual server. Associate the Form Template with a Form Library 1. Create a new form library (or use an existing one, it really doesn't matter),go to the settings page. and choose Advanced Settings. 2. Choose Yes for Allow management of content types. For Opening browser-enabled documents, choose Display as a web page. 3. Click the OK button to go back to the Form Library Settings page. 4. There should now be a Content Types section which displays the Content Types enabled for the form library. The form template feature that you activated added a new content type to the Site Content Type Gallery. 5. Choose Add from existing site content types and find your form template. Click on it and click Add, then click OK. 6. Go back to your form library, click the New dropdown, and choose your form template. It will be opened in the browser window where it can be filled out and saved or submitted.

http://geekswithblogs.net/jgmeyer/archive/2006/06/26/83087.aspx