Sharepoint API - 如何从 ASP.NET Web 应用程序将文件上传到 Sharepoint Doc Library [英] Sharepoint API - How to Upload files to Sharepoint Doc Library from ASP.NET Web Application

查看:14
本文介绍了Sharepoint API - 如何从 ASP.NET Web 应用程序将文件上传到 Sharepoint Doc Library的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am new to Sharepoint Server, Do we have any utility to upload files from ASP.NET application.

能否提供您宝贵的答案?

Could you please provide your valuable answers?

推荐答案

您可以编写一些自定义代码来实现.如果您在同一台服务器上或使用 WebServices,则可以使用 SharePoint API

You can write some custom code to do it. You could use the SharePoint API if you are on the same server or use WebServices

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

Here is the sample code assuming that you know the url of the document library and you are uploading the document to the root folder. You will have to add Microsoft.SharePoint.dll as reference to your ASP.NET project

        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();
                    }
                }
            }
        }

这篇关于Sharepoint API - 如何从 ASP.NET Web 应用程序将文件上传到 Sharepoint Doc Library的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆