1

i have an InfoPath 2007 file which includes code to generate a signed PDF out of the current infopath form. Now i want to upload this PDF via C# code into a sharepoint 2010 library.

I tried

            SPSite objSite = new SPSite(spSite);
            SPFolder objFolder = objSite.OpenWeb().GetFolder(spLibraryName);
            string sourcePath = document;


            FileInfo fi = new FileInfo(sourcePath);
            int fileSize = (int)fi.Length;
            SPFileCollection objFiles = objFolder.Files;
            byte[] myFile = new byte[fileSize];
            FileStream mystream = new System.IO.FileStream(sourcePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
            mystream.Read(myFile, 0, fileSize);
            mystream.Close();
            string strFileUrl = document;
            SPFile spf = objFiles.Add(strFileUrl, myFile);

but it did not work because the SPSite could not be created /found.

Now i want to know if it is possible to use a dataConnection to put the PDF-file through.

How can i solve this?

thank you, el

0

1 Answer 1

1

Call EnsureParentFolder(SPWeb parentSite, string destinUrl) first, before you add the file to the collection.

http://msdn.microsoft.com/en-us/library/ms454491.aspx

http://msdn.microsoft.com/en-us/library/dd587349%28v=office.11%29.aspx

5
  • i'll give it a try. Previously i have to upgrade to Sharepoint 2010 standard edition because i am running SP Foundation :( I hope this will help me out too
    – elCapitano
    Commented Mar 29, 2012 at 9:25
  • nope, nothing helped :( I even can not create the SPWeb Object.. therefore the ensureParentFolder is not able to help
    – elCapitano
    Commented Apr 1, 2012 at 11:23
  • Are you sure your Uri for spSite is valid? Is the SPSite object being created successfully? Commented Apr 2, 2012 at 12:27
  • I can access the URI from IE and it works well. I dont know what i can do
    – elCapitano
    Commented Apr 3, 2012 at 7:29
  • OK, so let's backtrack a second here. In your post it says you can not create SPSite. Is this still true? Then you said you can not create SPWeb. Is this still true? Have you used the debugger to step line by line verifying the data you are passing? Finally, the value of strFileUrl should be the destination Url, not the source Url. Concatenate the destination folder Url, a \, and the desired filename. See: msdn.microsoft.com/en-us/library/ms367739.aspx Commented Apr 3, 2012 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.