请问要怎样修改才能上载多个文档 private void FileUpload(string fileurl, string filename, string strGuid)
{
SPSecurity.RunWithElevatedPrivileges(delegate()//模仿管理员的权限进行操作(代码访问权限提升)
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))//实例化SPWeb对象才能保证执行者是管理员
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID])
{
web.AllowUnsafeUpdates = true; string Path = @"D:\Folder\" + filename;
this.FileUpload1.SaveAs(Path);
fileurl = Path;
SPList Mylist = web.Lists["项目申请"];
FileStream fstream = File.OpenRead(fileurl);//以文件流的形式读取文件源
byte[] contens = new byte[fstream.Length];//定义一个直接数组
fstream.Read(contens, 0, (int)fstream.Length);//把文件源写入到数组容器
fstream.Close();//关闭文件流
String url = "";
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='sGUID'/><Value Type='Text'>" + strGuid + @"</Value></Eq>
</Where>";
SPListItemCollection myItems = Mylist.GetItems(query);
//SPListItemCollection myItems = Mylist.Items;
foreach (SPListItem item in myItems)
{
string psGuid = item["sGUID"].ToString();
if (psGuid == strGuid)
{
if (item.Attachments.Count > 0)
{
Response.Write("<script language=javascript>alert('该申请文档已经提交,请不要重复提交!')</script>");
}
else
{
SPAttachmentCollection attach = item.Attachments;
url = attach.UrlPrefix;
attach.Add(filename, contens);
item.Update();
File.Delete(Path);
}
break;
}
} }
}
});
}
{
SPSecurity.RunWithElevatedPrivileges(delegate()//模仿管理员的权限进行操作(代码访问权限提升)
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))//实例化SPWeb对象才能保证执行者是管理员
{
site.AllowUnsafeUpdates = true;
using (SPWeb web = site.AllWebs[SPContext.Current.Web.ID])
{
web.AllowUnsafeUpdates = true; string Path = @"D:\Folder\" + filename;
this.FileUpload1.SaveAs(Path);
fileurl = Path;
SPList Mylist = web.Lists["项目申请"];
FileStream fstream = File.OpenRead(fileurl);//以文件流的形式读取文件源
byte[] contens = new byte[fstream.Length];//定义一个直接数组
fstream.Read(contens, 0, (int)fstream.Length);//把文件源写入到数组容器
fstream.Close();//关闭文件流
String url = "";
SPQuery query = new SPQuery();
query.Query = @"<Where><Eq><FieldRef Name='sGUID'/><Value Type='Text'>" + strGuid + @"</Value></Eq>
</Where>";
SPListItemCollection myItems = Mylist.GetItems(query);
//SPListItemCollection myItems = Mylist.Items;
foreach (SPListItem item in myItems)
{
string psGuid = item["sGUID"].ToString();
if (psGuid == strGuid)
{
if (item.Attachments.Count > 0)
{
Response.Write("<script language=javascript>alert('该申请文档已经提交,请不要重复提交!')</script>");
}
else
{
SPAttachmentCollection attach = item.Attachments;
url = attach.UrlPrefix;
attach.Add(filename, contens);
item.Update();
File.Delete(Path);
}
break;
}
} }
}
});
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货