我需要在SharePoint文档库中创建一个简单的文件夹,但我似乎无法找到文件的关于这一主题的废料。
该DWS Web服务似乎是用来创建一个工作空间物理文件夹,我需要一种方法来创建一个文档库中的文件夹。
不知道该怎么办,请大家帮忙
我需要在SharePoint文档库中创建一个简单的文件夹,但我似乎无法找到文件的关于这一主题的废料。
该DWS Web服务似乎是用来创建一个工作空间物理文件夹,我需要一种方法来创建一个文档库中的文件夹。
不知道该怎么办,请大家帮忙
我发现这个方法的工作:
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();
这对于使用在阿帕奇JAVA类似的请求的代码的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;
}
代码来创建HttpClient的,并调用makeFolder功能
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider().setCredentials(
AuthScope.ANY,
new NTCredentials(config.getUserName(), config.getPasswords(),
"", config.getDomain()));
我知道这是一个很老的问题,但如果别人发现了,这是多么我已经做到了:
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方法等方面
我已经做了Web服务的一些工作,但我无法找到创建一个文件夹的任何代码。 但是,我认为使用UNC路径从网络共享文件复制到一个现有的文件夹中的SharePoint文档库中有代码。 它采用有System.IO.File - 也许你可以使用该技术来创建一个文件夹?
通过创建在SharePoint文件夹中的文档工作区的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('"', '-'), @"[.~#%&*{}:<>?|/]", "-");
}