June 2006 - Posts - Agni Reddy
in

InfoPath Dev

Agni Reddy

June 2006 - Posts

  • Open an InfoPath File from a Web Page

    There are times when you get data from a DB and want to throw an xml file from a web page. To do that, in your aspx code you would have to build the InfoPath xml with the PI information using methods in the System.Xml namespace (or StringBuilder String.Format etc). This xml string is then given as input to the SendContent function shown below. This function should also be added to the code running behind the aspx page.

    public static void SendContent(string content)
    {
        if(content == null || content == String.Empty)
            return;

        Response.Clear();
        byte []bytes = Encoding.UTF8.GetBytes(content);
        Response.AddHeader("Content-Disposition", "attachment; filename=MyFileName.Xml");
        Response.ContentType = "text/xml"; 
        Response.AddHeader("Content-Length", bytes.Length.ToString());
        Response.Write(content);
        Response.End();
    }

    This will throw up a dialog box with the file name specified in the filename=MyFileName.Xml where the user will be asked to either Open, Save or Cancel. When Open is clicked the file will open InfoPath using the solution PI provided. But the code above shows a regular xml icon in the Open/Save/Cancel dialog box. If you want to change this to show an InfoPath Icon instead change the following line of code:

    Response.AddHeader("Content-Disposition", "attachment; filename=MyFileName.Xml");

    As follows:

    Response.AddHeader("Content-Disposition", "attachment; filename=MyFileName.infopathXml");

    You can also change the file name to be more pertinent by getting some data from the xml string and putting that information instead of MyFileName.

  • Get Name of Person Logged Into SharePoint

    Generally it's not possible to get the logged in username of the person logged into SharePoint. To do this we need to first create a file and query the modified name from the SharePoint form library for this file. Once we get the name we then delete this file. This document explains how to do this.

    1. Add a Sharepoint Submit data connection named SharePointSubmit to the solution.
    2. In the OnLoad code of the solution, add code to submit this form to SharePoint:

    DAVAdapter sharePoint = (DAVAdapter)thisXDocument.DataAdapters["SharePointSubmit"]; 
    sharePoint.Submit();

    1. Then follow the Query for Items in SharePoint Form Library Using GetListItems Web Method how to article to get the details of this form using GetListItems SharePoint Web service function.
    2. Add the following code into the FormCode.cs of the solution:

    // Pass the GetlistItem node received from the previous step into this method.

    private string getUserName(IXMLDOMNode getListItemsResult)

    {

        string userName = getListItemsResult.selectNodes("//rs:data/z:row/@ows_Editor");

        // To get the Modified Username from the SharePoint Form Library.
        userName = userName.Substring(4);

        // "20;#" characters occur before user name. This method skips the mysterious characters.
        return userName;
    }

    1. Now delete this file using the UpdateListItems SharePoint Web service function. Details on how to use this function are in the Delete File from SharePoint how to article.
    2. You can use this username where ever you need the logged in SharePoint user name.
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.