Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i AM GETTING THIS ERROR:

System.IO.DirectoryNotFoundException: There is no file with URL 'Bill/dbReportProceduresNew' in this Web

i am adding document from asp.net web application to sharepoint document library.

how to handle this exception.

MY CODE:
------------
C#
protected void btnUpload_Click(object sender, EventArgs e)
        {
            SPSite mySite = SPContext.Current.Site;
            //SPSite mySite = new SPSite("http://sel038dt2008:20006/");
            SPWeb myWeb = mySite.OpenWeb();
            UploadDocument(myWeb);
        }
        
        public void UploadDocument(SPWeb site)
        {
            if (FileUpload1.HasFile)
            {
                SPFolder folder = site.GetFolder("Bill");

                SPFileCollection files = folder.Files;

                Stream fStream = FileUpload1.PostedFile.InputStream; //path of the file to upload

                byte[] contents = new byte[fStream.Length];

                fStream.Position = 0;

                fStream.Read(contents, 0, (int)fStream.Length);

                fStream.Close();

                string Filename = FileUpload1.FileName;

                //string URL = SPContext.Current.Site.Url + "/Bill/" + Filename;
                site.Files.Add(SPContext.Current.Site.Url + "/Bill/" + Filename, contents);
                //site.Files.Add("http://sel038dt2008:20006/Bill/" + Filename, contents);
                //SPFile currentFile = files.Add(URL, contents);
            }
        }
Posted
Updated 2-Aug-12 20:55pm
v2
Comments
Sebastian T Xavier 3-Aug-12 2:55am    
Use of caps is not good

There is no file with URL 'Bill/dbReportProceduresNew' in this Web
Error says all. File path you have given to add the file is not valid. Make sure the path used is correct and file exists in that path.

Either, use a absolute path directly OR use a correct relative path. You would need to make sure that the path is correct such that file is found and used.

For relative path, you can try this Tip and resolve the path correctly before setting the source of the file: Resolving Paths in a Multi-Folder WebSite[^]
 
Share this answer
 
v2
As Sandeep said, There is no file with requested URL. But if you have a file in your solution directory then you can try this:
C#
site.Files.Add("~/Bill/" + Filename, contents);



--Amit
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900