How to upload a file to MOSS document in InfoPath Form
hi,
I develope a workflow on MOSS2007 using VS2005 and InfoPath, I have upload a file to MOSS document in InfoPath Form, I don't know what to do, please help, thanks.
hi,
I develope a workflow on MOSS2007 using VS2005 and InfoPath, I have upload a file to MOSS document in InfoPath Form, I don't know what to do, please help, thanks.
I would love to see what you've done. I'm just getting ready to start on a project using SharePoint, windows workflow and infopath.
Any code / advice on where to start?
Allen,
I'm a little uncertain of what you are trying to do. Is the IP form your payload document or the workflow forms (association/initiation)? If you can clarify and perhaps explain a little more, I'll try to help.
-Dave
thanks Dave, my workflow using InfoPath form ,and i will uploads a document via a task using an InfoPath Form. But the attached File Control in InfoPath is not work(can't upload a file successful).
Sorry, my English is pool.
Allen
Allen,
If you are trying to use the 'File Attachment' control to do the upload to SP, it wouldn't work. This control is for ATTACHING a file to the IP form only.
Allen:
As the other poster mentioned, the AttachFile control in IP (InfoPath) is only for attaching a file to the IP form - it does not get the document into SharePoint. I think the approach you are looking for is this:
1. User browses to a SharePoint site
2. User makes use of SharePoint's native file upload capabilities to add document to a document library
3. The DocLib is configured to automatically kick off a workflow when a file is added, or user kicks it off manually
4. Workflow is kicked off. The first thing it does is present an IP form (rendered through Forms Server/Services) to the user to collect more information, etc
5. Workflow can also assign Tasks to people and when they open the Task, they will see a custom IP form, rendered through Forms Server/Services
If some flavor of that is not what you are looking for, post back with clarification and I'll see what I can do to help
-Dave
Thanks all .
I want to attaching a file to sharepoint document library via a task with infopath forms, when workflow has been runing.
Best Regard.
Allen
Hi Allen,
I am trying to do the same thing at the moment, I'll let you know how I get on. I guess the InfoPath form server FileAttachment control isnt working properly through IE. I get a message File could not be attached.
Anyway let me know if you have any success and I will also.
Regards
Simon
Allen,
Are you using a custom aspx page to host the infopath form? if so take a look at this msdn post.
http://msdn2.microsoft.com/en-us/library/aa701078.aspx
I am not but wondering if the wrktaskip.aspx page needs the same treatment.
Regards
Simon
To get the file upload to work do the following edit wrktaskip.aspx
from C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS directory
Add the follow to thate page under the PlaceHolderMain section, note the script type tag = "text [forward slash] javascript"
do an iisreset and try the file upload it seems to work well.
This blog post gave me all the details:-
http://chrissyblanco.blogspot.com/2006/07/workflow-that-uploads-document-via.html
<script type="text/javascript">
document.aspnetForm.encoding = "multipart/form-data";
</script>
<asp:Content ContentPlaceHolderId="PlaceHolderMain" runat="server">
<script type="text/javascript">
document.aspnetForm.encoding = "multipart/form-data";
</script>
<SharePoint:FormComponent TemplateName="WorkflowEditFormToolBar" ControlMode="Edit" runat="server"/>
<table class="ms-informationbar" style="margin-top: 10px;" border="0" cellpadding="2" cellspacing="0"
width="100%"
>
<tr>
<td width="10" valign="center" style="padding: 4px;">
<img IMG SRC="/_layouts/images/Workflows.gif" alt=<%SPHttpUtility.AddQuote(SPHttpUtility.HtmlEncode(GetLocString("WrkTask_PageTitle")),Response.Output);%>/>
</td>
<td>
<% SPHttpUtility.NoEncode(m_pageDescription,Response.Output); %>
</td>
</tr>
</table>
<InfoPath:XmlFormView id="XmlFormControl" runat="server"
style="width:100%;"
/>
<SharePoint:FormDigest runat=server/>
</asp:Content>
Cheers
Simon
Thanks Simon, I could receive data from InfoPath web in workflow, but i can't convert the Base64 data to original file.
This is my code about convertion:
Mothed 1:
string fstring = Task0AfterProps.ExtendedProperties["Upfile1"].ToString();
char[] arrFile = new char[fstring.Length];
for (Int32 i = 0; i < fstring.Length; i++)
arrFile[i] = fstring[i];
byte[] f = Convert.FromBase64CharArray(arrFile, 0, arrFile.Length);
string filep = "/Doc/Documents/tempfilename.doc";
workflowProperties.Web.Files.Add(filep, fff); //this code thow a exception
Mothed 2:
byte[] f = Convert.FromBase64String(Task0AfterProps.ExtendedProperties["Upfile1"].ToString());
string filep = "/Doc/Documents/tempfilename.doc";
workflowProperties.Web.Files.Add(filep, fff); //this code thow a exception
It should how do this.
Allen
Allen,
Yeah I had a similar problem and its down to the fact you are not converting the byte array correctly and also you are not using the full url to the file from the filescollection this is how I did itb (I have taken some of the code from the previous posts mentioned above)
Hope this helps
Regards
Simon
:-
private bool UploadBase64FileToSP(SPFolder destinationFolder, string sFileName, string base64String){
bool bSuccess = false; try{
if (base64String != String.Empty){
// Position 20 contains a DWORD indicating the length of the // filename buffer. The filename is stored as Unicode so the // length is multiplied by 2. byte[] base64bytes = Convert.FromBase64String(base64String); int fnLength = base64bytes[20] * 2; byte[] fnBytes = new byte[fnLength]; // The actual filename starts at position 24 . . . for (int i = 0; i < fnLength; ++i){
fnBytes
= base64bytes[24 + i];
}
// Convert the filename bytes to a string. The string // terminates with \0 so the actual filename is the // original filename minus the last character ! char[] charFileName = UnicodeEncoding.Unicode.GetChars(fnBytes); string fileName = new string(charFileName);fileName = fileName.Substring(0, fileName.Length - 1);
// The file is located after the header, which is 24 bytes long // plus the length of the filename. byte[] fileContents = new byte[base64bytes.Length - (24 + fnLength)]; for (int i = 0; i < fileContents.Length; ++i){
fileContents
= base64bytes[24 + fnLength + i];
}
if (sFileName == String.Empty)sFileName = fileName;
string sFileUrl="";sFileUrl =
"/" + destinationFolder.Url + "/" + sFileName;sFileUrl = Microsoft.SharePoint.Utilities.
SPEncode.HtmlEncodePreserveSpaces(sFileUrl); SPFileCollection destFiles = destinationFolder.Files; if (destFiles != null){
destFiles.Add(sFileUrl, fileContents);
bSuccess =
true;}
}
else throw new Exception("Base64String is empty - aborting upload");}
catch (Exception ex){
PostToHistoryLog(
"Error Occured: UploadResultsFile", "", "Msg: " + ex.Message + " Stack: " + ex.StackTrace); throw ex;}
return bSuccess;}