Sharepoint 如何在当前文档库中创建文件夹(如果它是';现在还没有?

Sharepoint 如何在当前文档库中创建文件夹(如果它是';现在还没有?,sharepoint,document-library,Sharepoint,Document Library,我修改了密码。我现在可以上传到当前的文档库(不再硬编码文档库或acutal url)。我现在需要做的就是确认文件夹是否存在。创建当前文档库中不存在的文件夹。如果遇到解决方案,我将继续更新代码 谢谢 public override void ItemAdded(SPItemEventProperties properties) { base.ItemAdded(properties); using (SPSite currentSite = new SPSite(propert

我修改了密码。我现在可以上传到当前的文档库(不再硬编码文档库或acutal url)。我现在需要做的就是确认文件夹是否存在。创建当前文档库中不存在的文件夹。如果遇到解决方案,我将继续更新代码

谢谢

public override void ItemAdded(SPItemEventProperties properties)
{
    base.ItemAdded(properties);


    using (SPSite currentSite = new SPSite(properties.WebUrl))
    using (SPWeb currentWeb = currentSite.OpenWeb())

    {   SPListItem oItem = properties.ListItem;             
        string doclibname = "Not a doclib";

        //Gets the name of the document library
        SPList doclibList = oItem.ParentList;

        if (null != doclibList)
        {
            doclibname = doclibList.Title;
        }
        // this section also not working.
        // getting Object reference not set to an instance of an object or something like that.
        //if (currentWeb.GetFolder("uHippo").Exists == false)
        //{

            SPListItem folder = doclibList.Folders.Add(doclibList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, "uHippo");
            folder.Update();
        //}

    }
} 
假设“doclibList”是您要在其中创建文件夹的文档库,您只需遍历其中的文件夹并检查是否找到必要的名称。如果doclibList不为null,请在检查后输入以下内容

bool foundFolder = false; //Assume it isn't there by default
if (doclibList.Folders.Count > 0) //If the folder list is empty, then the folder definitely doesn't exist.
{
  foreach (SPListItem fItem in doclibList.Folders) 
  {
    if (fItem.Title.Equals("uHippo"))
    {
      foundFolder = true; //Folder does exist, break loop.
      break;
    }
  }
}
if (foundFolder == false) 
{
  SPListItem folder = doclibList.Folders.Add(doclibList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, "uHippo");      
  folder.Update(); 
}
假设“doclibList”是您要在其中创建文件夹的文档库,您只需遍历其中的文件夹并检查是否找到必要的名称。如果doclibList不为null,请在检查后输入以下内容

bool foundFolder = false; //Assume it isn't there by default
if (doclibList.Folders.Count > 0) //If the folder list is empty, then the folder definitely doesn't exist.
{
  foreach (SPListItem fItem in doclibList.Folders) 
  {
    if (fItem.Title.Equals("uHippo"))
    {
      foundFolder = true; //Folder does exist, break loop.
      break;
    }
  }
}
if (foundFolder == false) 
{
  SPListItem folder = doclibList.Folders.Add(doclibList.RootFolder.ServerRelativeUrl, SPFileSystemObjectType.Folder, "uHippo");      
  folder.Update(); 
}