Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将文档上载到文档库中的子文件夹_C#_Sharepoint 2007 - Fatal编程技术网

C# 将文档上载到文档库中的子文件夹

C# 将文档上载到文档库中的子文件夹,c#,sharepoint-2007,C#,Sharepoint 2007,我正在尝试使用对象模型将文档(含元数据)上载到文档库中的文件夹。我可以添加元数据,但无法将文件添加到该项目 using (SPSite site = new SPSite(SPContext.Current.Web.Url)) { using (SPWeb web = site.OpenWeb()) { fContents = DataByteArray(fuDocument.PostedFile.ContentLength, fuDocument.File

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

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;
  }
使用(SPSite站点=新SPSite(SPContext.Current.Web.Url))
{
使用(SPWeb=site.OpenWeb())
{
fContents=DataByteArray(fuDocument.PostedFile.ContentLength,fuDocument.FileContent);
SPList docLib=SPContext.Current.Web.Lists[this.ListName];
SPQuery query=新建SPQuery();
query.query=“”;
SPListItemCollection listItems=docLib.GetItems(查询);
SPListItem folder=GetFolderInList(docLib,docLib.RootFolder,“测试”);
SPListItem=folder.ListItems.Add(folder.folder.ServerRelativeUrl,SPFileSystemObject.File);
//我不知道如何将文件添加到列表中,请帮助
项目[“项目编号”]=tbprojectNumber.Text;
item.Update();
}
}
私有SPListItem GetFolderInList(SPList父列表、SPFolder父文件夹、字符串folderName)
{
folderName=folderName.ToLower();
字符串parentFolderUrl=parentFolder==null?”:parentFolder.ServerRelativeUrl.ToLower();
//查找现有文件夹
foreach(parentList.Folders中的SPListItem f)
{
如果(f.Folder.ServerRelativeUrl.ToLower()==parentFolderUrl+“/”+folderName)
返回f;
}
返回null;
}
谢谢