我需要在SharePoint的文档库中创建一个简单的文件夹,但我似乎无法找到有关该主题的文档。
dws webservice似乎用于在工作区中创建物理文件夹,我需要一种在文档库中创建文件夹的方法。
不确定该怎么做,请帮忙
答案 0 :(得分:4)
我发现这种方法有效:
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();
答案 1 :(得分:2)
这是使用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()));
答案 2 :(得分:0)
我已经完成了Web服务的一些工作,但我找不到任何创建文件夹的代码。但是,我有使用UNC路径将文件从网络共享复制到SharePoint文档库中的现有文件夹的代码。它使用System.IO.File - 也许您可以使用该技术创建文件夹?
答案 3 :(得分:0)
我知道这是一个非常古老的问题,但是如果有其他人发现它,我就是这样做的:
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方法以其他方式完成
答案 4 :(得分:0)
使用Document Workspace Web Service (Dws)在sharepoint中创建文件夹。效果很好。
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('"', '-'), @"[.~#%&*{}:<>?|/]", "-");
}