Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

1 Answer 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

share|improve this answer
    
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 Mar 29 '12 at 9:25
    
nope, nothing helped :( I even can not create the SPWeb Object.. therefore the ensureParentFolder is not able to help –  elCapitano Apr 1 '12 at 11:23
    
Are you sure your Uri for spSite is valid? Is the SPSite object being created successfully? –  RJ Cuthbertson Apr 2 '12 at 12:27
    
I can access the URI from IE and it works well. I dont know what i can do –  elCapitano Apr 3 '12 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 –  RJ Cuthbertson Apr 3 '12 at 18:25

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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