How can I retrieve the current InfoPath document's URL from the SharePoint Forms Library? (MOSS w/InfoPath)
- 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
解答
- 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- 已標示為解答Lambert QinMSFT, 版主Wednesday, 14 January, 2009 8:36
Hi,
Use the below statement to get the document url from SharePoint,
http://<SharepointServerName>/<SiteName>/<FormLibraryName>/<DocumentName>.docx
Hope this helps.
Rajitha- 已標示為解答Lambert QinMSFT, 版主Wednesday, 14 January, 2009 8:36
- 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- 已標示為解答Lambert QinMSFT, 版主Wednesday, 14 January, 2009 8:36
所有回覆
- 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- 已標示為解答Lambert QinMSFT, 版主Wednesday, 14 January, 2009 8:36
Hi,
Use the below statement to get the document url from SharePoint,
http://<SharepointServerName>/<SiteName>/<FormLibraryName>/<DocumentName>.docx
Hope this helps.
Rajitha- 已標示為解答Lambert QinMSFT, 版主Wednesday, 14 January, 2009 8:36
- 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 - 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- 已標示為解答Lambert QinMSFT, 版主Wednesday, 14 January, 2009 8:36

