if (context.Request.Files.Count > 0)
{
string strUrl = "http://XXXXXXXXXXX:8080/sites/home";
Microsoft.SharePoint.SPSecurity.RunWithElevatedPrivileges(delegate ()
{
using (SPSite site = new SPSite(strUrl))
{
using (SPWeb web = site.OpenWeb(""))
{
web.AllowUnsafeUpdates = true;
SPList list = web.Lists["文档"]; //考虑到中英文的影响,这个在英文状态下名称可能需要改变
if (list != null)
{
SPFolder folder = list.RootFolder;
HttpFileCollection files = context.Request.Files;
if (files.Count > 0)
{
for (int i = 0; i < files.Count; i++)
{
HttpPostedFile file = files[i];
string onlyName = System.IO.Path.GetFileName(file.FileName);
string urlOfFile = DateTime.Now.ToString("yyyyMMddhhmmss") + onlyName;
SPFile oFile = folder.Files.Add(urlOfFile, file.InputStream, true);
oFile.Update();
}
}
}
web.AllowUnsafeUpdates = false;
}
}
});
context.Response.Write("Success");
}
else
{
context.Response.Write("没有数据");
}