我修改了代码。我现在可以上传到当前文档库(不再对文档库或实际 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();
//}
}
}