代码之家  ›  专栏  ›  技术社区  ›  JL. Hans Passant

sharepoint:如何在文档库中创建文件夹请使用web服务

  •  3
  • JL. Hans Passant  · 技术社区  · 15 年前

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

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

    不知道该怎么办,请帮忙

    5 回复  |  直到 10 年前
        1
  •  4
  •   JL. Hans Passant    15 年前

    我发现这种方法有效:

        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();
    
        2
  •  2
  •   David Pitchford    12 年前

    这是使用Apache HTTP客户端的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()));
    
        3
  •  0
  •   Mayo    15 年前

    我已经在Web服务上做了一些工作,但是我找不到任何创建文件夹的代码。但是,我有使用unc路径将文件从网络共享复制到sharepoint文档库中现有文件夹的代码。它使用system.io.file—也许您可以使用这种技术创建一个文件夹?

        4
  •  0
  •   pclem12    14 年前

    我知道这是一个很老的问题,但如果有人发现了,我就是这么做的:

           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方法进行其他方式。

        5
  •  0
  •   Siddique Mahsud    10 年前

    使用在sharepoint中创建文件夹 Document Workspace Web Service (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('"', '-'), @"[.~#%&*{}:<>?|/]", "-");
    }
    
    推荐文章