Post by 570enrico on May 23, 2011 3:18:08 GMT -6
Hi
i'm new in programming SharePoint and i must realize an .NET application tha upload file in a document library and change the document propriety in this document library. In google i have found the nex code:
String fileToUpload = @"D:\TestSP.txt";
String sharePointSite = "http://yoursite.com/sites/Research/";
sharePointSite = "http://milsharep01/home.aspx";
String documentLibraryName = "Shared Documents";
using (SPSite oSite = new SPSite(sharePointSite))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
if (!System.IO.File.Exists(fileToUpload))
throw new FileNotFoundException("File not found.", fileToUpload);
SPFolder myLibrary = oWeb.Folders[documentLibraryName];
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = System.IO.Path.GetFileName(fileToUpload);
FileStream fileStream = File.OpenRead(fileToUpload);
// Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
// Commit
myLibrary.Update();
}
}
when i try to execute appeare the next error message:
"
The Web application at http://milsharep01/home.aspx could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."
in istruction new SPSite(sharePointSite).
Where is my mistake? How can i do for solve this situation?
Where can i found some lab tha explain how solve my problem?
Thanks in advance
i'm new in programming SharePoint and i must realize an .NET application tha upload file in a document library and change the document propriety in this document library. In google i have found the nex code:
String fileToUpload = @"D:\TestSP.txt";
String sharePointSite = "http://yoursite.com/sites/Research/";
sharePointSite = "http://milsharep01/home.aspx";
String documentLibraryName = "Shared Documents";
using (SPSite oSite = new SPSite(sharePointSite))
{
using (SPWeb oWeb = oSite.OpenWeb())
{
if (!System.IO.File.Exists(fileToUpload))
throw new FileNotFoundException("File not found.", fileToUpload);
SPFolder myLibrary = oWeb.Folders[documentLibraryName];
// Prepare to upload
Boolean replaceExistingFiles = true;
String fileName = System.IO.Path.GetFileName(fileToUpload);
FileStream fileStream = File.OpenRead(fileToUpload);
// Upload document
SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);
// Commit
myLibrary.Update();
}
}
when i try to execute appeare the next error message:
"
The Web application at http://milsharep01/home.aspx could not be found. Verify that you have typed the URL correctly. If the URL should be serving existing content, the system administrator may need to add a new request URL mapping to the intended application."
in istruction new SPSite(sharePointSite).
Where is my mistake? How can i do for solve this situation?
Where can i found some lab tha explain how solve my problem?
Thanks in advance