gpt4 book ai didi

asp.net - Sharepoint API-如何从ASP.NET Web应用程序将文件上传到Sharepoint文档库

转载 作者:行者123 更新时间:2023-12-04 04:14:25 26 4
gpt4 key购买 nike

我是Sharepoint Server的新手,我们是否有任何实用程序可以从ASP.NET应用程序上传文件。

您能提供宝贵的答案吗?

最佳答案

您可以编写一些自定义代码来做到这一点。如果您在同一服务器上或使用WebServices,则可以使用SharePoint API。

这是示例代码,假设您知道文档库的url,并且将文档上载到根文件夹。您将必须添加Microsoft.SharePoint.dll作为对ASP.NET项目的引用

        using (SPSite siteCollection = new SPSite(url))
{
using (SPWeb spWeb = siteCollection.OpenWeb())
{
SPList spList = spWeb.GetList(url);

string fileName = "XXXX";
FileStream fileStream = null;
Byte[] fileContent = null;

try
{
string docPath = XXXX; //physical location of the file
fileStream = File.OpenRead(docPath + fileName);
fileContent = new byte[Convert.ToInt32(fileStream.Length)];
fileStream.Read(fileContent, 0, Convert.ToInt32(fileStream.Length));

spList.RootFolder.Files.Add(spList.RootFolder.Url + "/" + fileName, fileContent, true);
spList.Update();
}
catch(Exception ex)
{

}
finally
{
if (fileStream != null)
{
fileStream.Close();
}
}
}
}

关于asp.net - Sharepoint API-如何从ASP.NET Web应用程序将文件上传到Sharepoint文档库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/279429/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com