SharePoint:如何使用 Web 服务在文档库中创建文件夹

发布于 2024-08-09 05:47:04 字数 138 浏览 6 评论 0原文

我需要在 SharePoint 的文档库中创建一个简单的文件夹,但我似乎找不到有关该主题的文档片段。

dws webservice 似乎用于在工作区中创建物理文件夹,我需要一种在文档库中创建文件夹的方法。

不知道该怎么办,请帮忙

I need to create a simple folder in a document library in SharePoint, but I can't seem to find a scrap of documentation on the subject.

The dws webservice seems to be used to create physical folders in a workspace, I need a way to create a folder in a document library.

Not sure what to do , please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

似梦非梦 2024-08-16 05:47:04

我发现这个方法有效:

    HttpWebRequest request = (System.Net.HttpWebRequest)HttpWebRequest.Create("http://mySite/MyList/MyfolderIwantedtocreate");
    request.Credentials = CredentialCache.DefaultCredentials;
    request.Method = "MKCOL";
    HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    response.Close();

I found this method to work :

    HttpWebRequest request = (System.Net.HttpWebRequest)HttpWebRequest.Create("http://mySite/MyList/MyfolderIwantedtocreate");
    request.Credentials = CredentialCache.DefaultCredentials;
    request.Method = "MKCOL";
    HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    response.Close();
苏大泽ㄣ 2024-08-16 05:47:04

这是使用 apache HttpClient 的 JAVA 中类似请求的代码

import org.apache.http.*;

private static HttpResponse makeFolder(
            String url,
            DefaultHttpClient httpClient) throws Exception {
    BasicHttpRequest httpPost = new BasicHttpRequest("MKCOL", url);
    HttpUriRequest httpUriRequest = new RequestWrapper(httpPost);

    HttpResponse status = httpClient.execute(httpUriRequest);
    EntityUtils.consume(status.getEntity());
    return status;
}

创建 httpClient 并调用 makeFolder 函数

DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(
        AuthScope.ANY,
        new NTCredentials(config.getUserName(), config.getPasswords(),
                        "", config.getDomain()));

This is the code for similar request in JAVA using apache HttpClient

import org.apache.http.*;

private static HttpResponse makeFolder(
            String url,
            DefaultHttpClient httpClient) throws Exception {
    BasicHttpRequest httpPost = new BasicHttpRequest("MKCOL", url);
    HttpUriRequest httpUriRequest = new RequestWrapper(httpPost);

    HttpResponse status = httpClient.execute(httpUriRequest);
    EntityUtils.consume(status.getEntity());
    return status;
}

Code to create the httpClient and call the makeFolder Function

DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(
        AuthScope.ANY,
        new NTCredentials(config.getUserName(), config.getPasswords(),
                        "", config.getDomain()));
自此以后,行同陌路 2024-08-16 05:47:04

我知道这是一个相当老的问题,但如果其他人发现它,我就是这样做的:

       String CAML =  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
            "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
        "<soap:Body>" +
        "<CreateFolder " + "xmlns=\"http://schemas.microsoft.com/sharepoint/soap/dws/\">"+
            "<url>" + ParentFolder+'/'+NewFolderName+ "</url>"+
        "</CreateFolder>"+
        "</soap:Body>" +
        "</soap:Envelope>";

       String uri = "http://[your site]/_vti_bin/dws.asmx";

       WebClient client = new WebClient();
        client.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/dws/CreateFolder";
        client.Headers["content-type"] = "text/xml; charset=utf-8";
        client.Encoding = Encoding.UTF8;
        client.UploadStringCompleted += UploadStringCompleted;
        try
        {
            client.UploadStringAsync(new Uri(uri, UriKind.Absolute), "POST", CAML);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error in upload string async: " + ex.Message);
        }

我使用的是 silverlight,这就是我使用上传字符串异步的原因,但这可以通过其他方式完成http post 方法

I know this is a pretty old question, but in case someone else finds it, this is how I've done it:

       String CAML =  "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
        "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" " +
            "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " +
            "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">" +
        "<soap:Body>" +
        "<CreateFolder " + "xmlns=\"http://schemas.microsoft.com/sharepoint/soap/dws/\">"+
            "<url>" + ParentFolder+'/'+NewFolderName+ "</url>"+
        "</CreateFolder>"+
        "</soap:Body>" +
        "</soap:Envelope>";

       String uri = "http://[your site]/_vti_bin/dws.asmx";

       WebClient client = new WebClient();
        client.Headers["SOAPAction"] = "http://schemas.microsoft.com/sharepoint/soap/dws/CreateFolder";
        client.Headers["content-type"] = "text/xml; charset=utf-8";
        client.Encoding = Encoding.UTF8;
        client.UploadStringCompleted += UploadStringCompleted;
        try
        {
            client.UploadStringAsync(new Uri(uri, UriKind.Absolute), "POST", CAML);
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error in upload string async: " + ex.Message);
        }

I was using silverlight, which is why I used upload string async, but this can be done other ways with the same http post method

迷迭香的记忆 2024-08-16 05:47:04

我已经使用 Web 服务完成了一些工作,但找不到任何创建文件夹的代码。但是,我有使用 UNC 路径将文件从网络共享复制到 SharePoint 文档库中的现有文件夹的代码。它使用 System.IO.File - 也许您可以使用该技术来创建文件夹?

I've done some work with the Web services but I can't find any code that creates a folder. However, I have code that copies files from a network share to an existing folder in a SharePoint document library using UNC paths. It uses System.IO.File - perhaps you could use that technique to create a folder?

匿名。 2024-08-16 05:47:04

使用 文档工作区 Web 服务 (Dws) 在共享点中创建文件夹)。效果很好。

public static bool CreateSPFolder(string FolderDir, string FolderName, yourCredentialsClass credentials)
{
    FolderName = ReplaceInvalidChars(FolderName);

    // create an instance of the sharepoint service reference
    Dws.Dws dwsWebService = new Dws.Dws();
    dwsWebService.Url = credentials.SharePointUrl + "/_vti_bin/Dws.asmx";
    dwsWebService.Credentials = new NetworkCredential(credentials.UserId, credentials.Password);

    string result = dwsWebService.CreateFolder(string.Format("{0}/{1}",FolderDir,FolderName));
    dwsWebService.Dispose();

    if (result == null)
    {
        throw new Exception("No response creating SharePoint folder");
    }

    if (result.Equals("<Result/>"))
    {
        return true;
    }

    return false;
}

public static string ReplaceInvalidChars(string strIn)
{
    return Regex.Replace(strIn.Replace('"', '-'), @"[.~#%&*{}:<>?|/]", "-");
}

Created folders in sharepoint by using Document Workspace Web Service (Dws). Works great.

public static bool CreateSPFolder(string FolderDir, string FolderName, yourCredentialsClass credentials)
{
    FolderName = ReplaceInvalidChars(FolderName);

    // create an instance of the sharepoint service reference
    Dws.Dws dwsWebService = new Dws.Dws();
    dwsWebService.Url = credentials.SharePointUrl + "/_vti_bin/Dws.asmx";
    dwsWebService.Credentials = new NetworkCredential(credentials.UserId, credentials.Password);

    string result = dwsWebService.CreateFolder(string.Format("{0}/{1}",FolderDir,FolderName));
    dwsWebService.Dispose();

    if (result == null)
    {
        throw new Exception("No response creating SharePoint folder");
    }

    if (result.Equals("<Result/>"))
    {
        return true;
    }

    return false;
}

public static string ReplaceInvalidChars(string strIn)
{
    return Regex.Replace(strIn.Replace('"', '-'), @"[.~#%&*{}:<>?|/]", "-");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文