if (FileUpload1.HasFile != false)
{
byte[] contents = GetFileContents(FileUpload1.PostedFile);
if (contents != null)
{
String url =
web.Lists[nameListDoc].RootFolder.ServerRelativeUrl.ToString();
SPFolderCollection oFolders = web.GetFolder(url).SubFolders;
oFolders.Add(nameNewFolder);
string folderString = nameListDoc+ "/" + nameNewFolder;
SPFolder oFolder = web.GetFolder(folderString);
SPFileCollection oFiles = oFolder.Files;
oFiles.Add(FileUpload1.FileName, contents);
}
}
private byte[] GetFileContents(HttpPostedFile postedFile)
{
HttpPostedFile file = postedFile;
Stream oStream = file.InputStream;
byte[] contents = new byte[oStream.Length];
oStream.Read(contents, 0, (int)oStream.Length);
oStream.Close();
oStream.Dispose();
return contents;
}
{
byte[] contents = GetFileContents(FileUpload1.PostedFile);
if (contents != null)
{
String url =
web.Lists[nameListDoc].RootFolder.ServerRelativeUrl.ToString();
SPFolderCollection oFolders = web.GetFolder(url).SubFolders;
oFolders.Add(nameNewFolder);
string folderString = nameListDoc+ "/" + nameNewFolder;
SPFolder oFolder = web.GetFolder(folderString);
SPFileCollection oFiles = oFolder.Files;
oFiles.Add(FileUpload1.FileName, contents);
}
}
private byte[] GetFileContents(HttpPostedFile postedFile)
{
HttpPostedFile file = postedFile;
Stream oStream = file.InputStream;
byte[] contents = new byte[oStream.Length];
oStream.Read(contents, 0, (int)oStream.Length);
oStream.Close();
oStream.Dispose();
return contents;
}
Спасибо, как раз это искал.
ОтветитьУдалить