将文档上载到Doc Library中的Sub文件夹

时间:2011-10-31 18:06:55

标签: c# sharepoint-2007

我正在尝试使用对象模型将文档(使用元数据)上传到文档库中的文件夹。我能够添加元数据,但我无法将文件添加到该项目

using (SPSite site = new SPSite(SPContext.Current.Web.Url)) 
{
using (SPWeb web = site.OpenWeb())                  
{
fContents = DataByteArray(fuDocument.PostedFile.ContentLength, fuDocument.FileContent);
SPList docLib = SPContext.Current.Web.Lists[this.ListName];
SPQuery query = new SPQuery();
query.Query = "<OrderBy><FieldRef Name='Created' Ascending='False' /></OrderBy>";
SPListItemCollection listItems = docLib.GetItems(query);
SPListItem folder = GetFolderInList(docLib, docLib.RootFolder, "Test");
SPListItem item = folder.ListItems.Add(folder.Folder.ServerRelativeUrl, SPFileSystemObjectType.File);

  // i don't know how to add the file to list,please help 

    item["Project Number"] = tbprojectNumber.Text;
    item.Update();

 }
 }



private SPListItem GetFolderInList(SPList parentList, SPFolder parentFolder, string folderName)
{
folderName = folderName.ToLower();
string parentFolderUrl = parentFolder == null ? "" : parentFolder.ServerRelativeUrl.ToLower();
//Look in existing folders
foreach (SPListItem f in parentList.Folders)
 {
 if (f.Folder.ServerRelativeUrl.ToLower() == parentFolderUrl + "/" + folderName)
  return f;
 }
 return null;
  }

由于

0 个答案:

没有答案