Microsoft Developer Network > Página principal de foros > SharePoint - InfoPath Forms Services > How can I retrieve the current InfoPath document's URL from the SharePoint Forms Library? (MOSS w/InfoPath)
Formular una preguntaFormular una pregunta
 

RespondidaHow can I retrieve the current InfoPath document's URL from the SharePoint Forms Library? (MOSS w/InfoPath)

  • martes, 06 de enero de 2009 19:58phamilton7733 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Hi,
     
    I am trying to figure out what should be a relatively simple operation.  I am using MOSS with InfoPath 2007.  I have a Forms Library that contains InfoPath documents that are set to only open within a Browser.  There is managed code with the InfoPath form and it is working properly within SharePoint Forms Services.

    I am trying to retrieve the full URL of the document that I am currently working with (I have opened from the Forms Library) from within Managed Code (C#), but I can't seem to do this.   What I am looking for is the simplest way to retrieve this information, it should exist somewhere as I have opened the document from SharePoint Forms Services.

    Ultimately, I would like to be able to set the Filename property of the FileSubmitConnection, but that appears to be read only, but I have the workaround for that one.  Just being able to read the current document's URL would be all I need.

    Thanks in advance....

    /Peter 
    Peter

Respuestas

  • martes, 06 de enero de 2009 22:01SYM Wong-A-Ton Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    phamilton7733 said:

    Hi,
     
    I am trying to figure out what should be a relatively simple operation.  I am using MOSS with InfoPath 2007.  I have a Forms Library that contains InfoPath documents that are set to only open within a Browser.  There is managed code with the InfoPath form and it is working properly within SharePoint Forms Services.

    I am trying to retrieve the full URL of the document that I am currently working with (I have opened from the Forms Library) from within Managed Code (C#), but I can't seem to do this.   What I am looking for is the simplest way to retrieve this information, it should exist somewhere as I have opened the document from SharePoint Forms Services.

    Ultimately, I would like to be able to set the Filename property of the FileSubmitConnection, but that appears to be read only, but I have the workaround for that one.  Just being able to read the current document's URL would be all I need.

    Thanks in advance....

    /Peter 


    Peter



    Have you already looked into the following solution which makes use of FormState?

    http://blogs.msdn.com/infopath/archive/2006/11/08/submitting-to-this-document-library.aspx

    S.Y.M. Wong-A-Ton, http://www.bizsupportonline.net
  • miércoles, 07 de enero de 2009 5:28RajithaS Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    Hi,

    Use the below statement to get the document url from SharePoint,

    http://<SharepointServerName>/<SiteName>/<FormLibraryName>/<DocumentName>.docx

    Hope this helps.

    Rajitha

  • miércoles, 07 de enero de 2009 17:50phamilton7733 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
    Thank you.  That was a great help. 

    I managed to get it working by using a few different techniques.  The "SaveLocation" input parameter isn't available unless this is a new document, so I needed to expand the sample a bit to get the information for an existing document as well as a new one. 

    I have it working and have included a code sample below (there is other stuff there, such as a web service call and I decided to include it anyhow):


      


    //You will need to declare a member variable for the sample below to work...

    private object _strUri

    {

    get { return FormState["_strUri"]; }

    set { FormState["_strUri"] = value; }

    }


    public void FormEvents_Loading(object sender, LoadingEventArgs e)  
      {  
       //To store the file name we will eventually save with  
       string fileName = "";  
     
       try 
       {  
     
        Boolean OpenedInBrowser = Application.Environment.IsBrowser;  
        // Find file name/location from the InputParameters  
        if (OpenedInBrowser)  
        {  
         if (e.InputParameters.ContainsKey("XmlLocation"))  //This is not a new document  
         {  
          FileSubmitConnection fileSubmitConnection =  
            (FileSubmitConnection)this.DataConnections["MAC Forms In SharePoint"]; //"Submit To Library"  
          string location = @fileSubmitConnection.FolderUrl;  
          location = location.Substring(0, location.IndexOf("/", 8));  
          _strUri = location + e.InputParameters["XmlLocation"].ToString();  
         }  
         else if (e.InputParameters.ContainsKey("SaveLocation"))  
         {  
          _strUri = Convert.ToString(e.InputParameters["SaveLocation"]);  
         }  
        }  
        else 
         //If it was opened in the client, we will get the Uri  
         _strUri = this.Template.Uri.ToString();  
     
        //This is how I determine whether this is a new document or not... 
        if (GetNode("/my:myFields/my:SubmittedOn").Value == "")  //This is a new document!  
        {  
         MAC_Form_Service_Host.DataService dataservice = GetDataService();  
     
         string sName = this.Application.User.UserName;  
     
         //Set the value of the "FileName" field.  This is what feeds the File Name property of the Data Connection for saving.  
         DateTime now = DateTime.Now;  
         fileName = sName + "_" + now.ToString("yyyy") + "_" + now.ToString("MM") + "_" + now.ToString("dd") + "_" + now.ToString("hh") + "_" + now.ToString("mm") + "_" + now.ToString("ss");  
        }  
       }  
       catch (Exception ex)  
       {  
        DisplayError(ex.ToString());  
       }  
      }  
     

    Peter

Todas las respuestas

  • martes, 06 de enero de 2009 22:01SYM Wong-A-Ton Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida
    phamilton7733 said:

    Hi,
     
    I am trying to figure out what should be a relatively simple operation.  I am using MOSS with InfoPath 2007.  I have a Forms Library that contains InfoPath documents that are set to only open within a Browser.  There is managed code with the InfoPath form and it is working properly within SharePoint Forms Services.

    I am trying to retrieve the full URL of the document that I am currently working with (I have opened from the Forms Library) from within Managed Code (C#), but I can't seem to do this.   What I am looking for is the simplest way to retrieve this information, it should exist somewhere as I have opened the document from SharePoint Forms Services.

    Ultimately, I would like to be able to set the Filename property of the FileSubmitConnection, but that appears to be read only, but I have the workaround for that one.  Just being able to read the current document's URL would be all I need.

    Thanks in advance....

    /Peter 


    Peter



    Have you already looked into the following solution which makes use of FormState?

    http://blogs.msdn.com/infopath/archive/2006/11/08/submitting-to-this-document-library.aspx

    S.Y.M. Wong-A-Ton, http://www.bizsupportonline.net
  • miércoles, 07 de enero de 2009 5:28RajithaS Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     Respondida

    Hi,

    Use the below statement to get the document url from SharePoint,

    http://<SharepointServerName>/<SiteName>/<FormLibraryName>/<DocumentName>.docx

    Hope this helps.

    Rajitha

  • miércoles, 07 de enero de 2009 17:37phamilton7733 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    Thanks.  I need to send an email with the address of the existing document that I am working with.  The issue was getting the full URL to the document within C#.  I have resolved this and will post back to the response above.

    Thanks.
    Peter
  • miércoles, 07 de enero de 2009 17:50phamilton7733 Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     RespondidaTiene código
    Thank you.  That was a great help. 

    I managed to get it working by using a few different techniques.  The "SaveLocation" input parameter isn't available unless this is a new document, so I needed to expand the sample a bit to get the information for an existing document as well as a new one. 

    I have it working and have included a code sample below (there is other stuff there, such as a web service call and I decided to include it anyhow):


      


    //You will need to declare a member variable for the sample below to work...

    private object _strUri

    {

    get { return FormState["_strUri"]; }

    set { FormState["_strUri"] = value; }

    }


    public void FormEvents_Loading(object sender, LoadingEventArgs e)  
      {  
       //To store the file name we will eventually save with  
       string fileName = "";  
     
       try 
       {  
     
        Boolean OpenedInBrowser = Application.Environment.IsBrowser;  
        // Find file name/location from the InputParameters  
        if (OpenedInBrowser)  
        {  
         if (e.InputParameters.ContainsKey("XmlLocation"))  //This is not a new document  
         {  
          FileSubmitConnection fileSubmitConnection =  
            (FileSubmitConnection)this.DataConnections["MAC Forms In SharePoint"]; //"Submit To Library"  
          string location = @fileSubmitConnection.FolderUrl;  
          location = location.Substring(0, location.IndexOf("/", 8));  
          _strUri = location + e.InputParameters["XmlLocation"].ToString();  
         }  
         else if (e.InputParameters.ContainsKey("SaveLocation"))  
         {  
          _strUri = Convert.ToString(e.InputParameters["SaveLocation"]);  
         }  
        }  
        else 
         //If it was opened in the client, we will get the Uri  
         _strUri = this.Template.Uri.ToString();  
     
        //This is how I determine whether this is a new document or not... 
        if (GetNode("/my:myFields/my:SubmittedOn").Value == "")  //This is a new document!  
        {  
         MAC_Form_Service_Host.DataService dataservice = GetDataService();  
     
         string sName = this.Application.User.UserName;  
     
         //Set the value of the "FileName" field.  This is what feeds the File Name property of the Data Connection for saving.  
         DateTime now = DateTime.Now;  
         fileName = sName + "_" + now.ToString("yyyy") + "_" + now.ToString("MM") + "_" + now.ToString("dd") + "_" + now.ToString("hh") + "_" + now.ToString("mm") + "_" + now.ToString("ss");  
        }  
       }  
       catch (Exception ex)  
       {  
        DisplayError(ex.ToString());  
       }  
      }  
     

    Peter