views:

35

answers:

1

RE: ASP:Upload control . Uploading into a SharePoint Document Library Subfolder and FILE NOT FOUND error

Two Issues, apparently unrelated.

I have subfolders like this /ApplicantDocuments/20 and /ApplicantDocuments/21 (where 20 and 21 are my subfolders and ApplicantDocuments is my library.

  1. The below function is erroring with file not found, but I confirmed I'm sending the fully qualify path (i.e c:\test.txt) to System.IO.FileStream content = System.IO.File.Open(documentFileName, System.IO.FileMode.Open);

  2. Even if it worked, looking at the code, I'm not using argument foldername. I'm passing 20 to the argument. How can I make sure it uploads into subfolder 20 of ApplicantDocuments?

The file is on my local client and I'm running Windows 7/ IE 8.

Thank you.

Just testing in test environment. Will tighten code once it works.

[code] public void UploadDocumentToSite(string foldername, string documentFileName) { SPSite siteCollection = new SPSite("https://xxxxxx"); SPWeb web = siteCollection.OpenWeb(); //SPSite.AllowUnsafeUpdates = true; //Web.AllowUnsafeUpdates = true; string Lib = "ApplicantDocuments"; SPFolder destFolder = web.GetFolder(Lib); sendmail(documentFileName+" "+foldername); System.IO.FileStream content = System.IO.File.Open(documentFileName, System.IO.FileMode.Open); destFolder.Files.Add(documentFileName, content, true); } [/code]

A: 
string Lib = "ApplicantDocuments"; 
SPFolder destFolder = web.GetFolder(Lib);

We have two overloads of SPWeb.GetFolder(). See Here One takes GUID and the other takes string that contains the server-relative URL for the folder. The best way is to get the folder using GUID. If you want to get the folder by name then you can use the folder code as well.

mydoclib = get reference to the doc lib here. then
SPFolder destFolder = mydoclib.rootFolder.SubFolders["20"];
Azher Iqbal