3

我可以使用 webclient 将文件上传到共享点,如下所示

using (System.Net.WebClient webclient = new System.Net.WebClient())
{
    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential(
                    Encryptor.Decrypt(ConfigurationManager.AppSettings["username"]),
                    Encryptor.Decrypt(ConfigurationManager.AppSettings["password"]),
                    ConfigurationManager.AppSettings["domain"]);
    webclient.Credentials = credentials;

    string path = Path.Combine("http://sharepoint.domain.com/dir", filename);
    webclient.UploadData(path, "PUT", fileBytes);
}

但是如果目录不存在,我不知道如何创建目录。

任何想法我该怎么做?

谢谢,-c

4

1 回答 1

3

SharePoint 网站中的“目录”一词具有欺骗性。SharePoint Web 服务的“目录”结构是位于 SharePoint 数据库中的虚拟结构。您需要确定 SharePoint 对象模型中的“目录”是什么对象,例如:http : //sharepoint.domain.com/dir 可能是一个 SPSite,在站点中,您可以拥有一个 SPFolders 的“目录”, SPLists、SPDocumentLibraries 等

因此,如果“创建不存在的目录”是指在 SharePoint 站点目录结构中,您将无法使用 WebClient。您有两个选择:Windows SharePoint Services 对象模型和 SharePoint Webservices。

在我看来,对象模型当然更容易使用,但它需要您在与 SharePoint 服务器相同的服务器上运行应用程序。Web 服务需要做更多的工作,但它使您能够远程使用它们。

您将需要确定您尝试添加的对象类型(例如 SPFolder、SPSite、SPList、SPDocumentLibrary 等)。

此处有大量使用对象模型的文档,但如果您想使用 Web 服务,您需要在以下位置访问它们:

Administration Service       http://<server-url:port-number>/_vti_adm/admin.asmx
Alerts Service               http://<server-url>/_vti_bin/alerts.asmx
Document Workspace Service   http://<server-url>/_vti_bin/dws.asmx
Forms Service                 http://<server-url>/_vti_bin/forms.asmx
Imaging Service             http://<server-url>/_vti_bin/imaging.asmx
List Data Retrieval Service http://<server-url>/_vti_bin/dspsts.asmx
Lists Service                 http://<server-url>/_vti_bin/lists.asmx
Meetings Service               http://<server-url>/_vti_bin/meetings.asmx
Permissions Service         http://<server-url>/_vti_bin/permissions.asmx
Site Data Service             http://<server-url>/_vti_bin/sitedata.asmx
Site Service                   http://<server-url>/_vti_bin/sites.asmx
Users and Groups Service       http://<server-url>/_vti_bin/usergroup.asmx
Versions Service               http://<server-url>/_vti_bin/versions.asmx
Views Service                 http://<server-url>/_vti_bin/views.asmx
Web Part Pages Service       http://<server-url>/_vti_bin/webpartpages.asmx
Webs Service                   http://<server-url>/_vti_bin/webs.asmx

我建议查看 Lists 或 Document Workspace Service 服务。

希望有帮助。

于 2009-05-08T17:06:13.010 回答