none
如何在WSS上创建文件夹(用httpwebrequest) RRS feed

  • 問題

  • ???WSS?????????,???????,?????????,????: 404 not found. ???????,???????????????????????

    I tried many times, something weird in this post, they can not dispaly correctly. I am trying to speak them out in english:)

    I just want to create a folder(say a document library) in WSS site, and I have codes below, they don't work yet, always raise an exception says: 404 not found. Can somebody be kind to help me out? Thank you guys in advance.

    public static void CreateDir_WebRequest() //under working...

    {

    string actionUrl = "http://localhost/_vti_bin/owssvr.dll?CS=109";

    string referUrl =

    "http://localhost/_layouts/1033/new.aspx?" +

    "ListTemplate=101&ListBaseType=1";

    string boundary = "----------" + DateTime.Now.Ticks.ToString("x");

    HttpWebRequest preRequest =

    (HttpWebRequest)HttpWebRequest.Create(referUrl);

    preRequest.UseDefaultCredentials = true;

    preRequest.KeepAlive = true;

    HttpWebResponse preResponse =

    (HttpWebResponse)preRequest.GetResponse();

    HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(actionUrl);

    request.Credentials = CredentialCache.DefaultCredentials;

    request.ContentType = "Application/x-www-form-urlencoded" + boundary;

    request.Method = "POST";

    request.Referer = referUrl;

    request.Accept = "*/*";

    request.KeepAlive = true;

    request.AllowAutoRedirect = true;

    for (int i = 0; i < preResponse.Cookies.Count; i++)

    {

    request.CookieContainer.Add(preResponse.CookiesIdea);

    }

    string requestString = null;

    requestString += HttpUtility.UrlEncode("--" + boundary);

    requestString += HttpUtility.UrlEncode("Title=\"CCC\"&");

    requestString += HttpUtility.UrlEncode("Description=\"CCC\"&");

    requestString += HttpUtility.UrlEncode("displayOnLeft=\"TRUE\"&");

    requestString += HttpUtility.UrlEncode("VersioningEnabled=\"FALSE\"&");

    requestString += HttpUtility.UrlEncode("DocumentTemplateType=101&");

    requestString += HttpUtility.UrlEncode("ListTemplate=1&");

    requestString += HttpUtility.UrlEncode("Project=\"http://localhost\"&");

    requestString += HttpUtility.UrlEncode("Cmd=\"NewList\"");

    byte[] data = Encoding.ASCII.GetBytes(requestString);

    request.ContentLength = data.Length;

    Stream writer = request.GetRequestStream();

    writer.Write(data, 0, data.Length);

    writer.Flush();

    writer.Close();

    HttpWebResponse response = (HttpWebResponse)request.GetResponse();

    string responseString = null;

    StreamReader reader = new StreamReader(response.GetResponseStream());

    responseString = reader.ReadToEnd();

    SaveStringToFile(responseString, "c:\\test\\CreateDir_WebRequest.txt");

    }

    2006年11月24日 上午 11:11

解答

  • I think it's OK for work.

    But, you must use WSS's Web Service interface to do your needs, and, your code might change for WSS Web Service interactions.

    If you want to call WSS managed library directly, please implement a middle component (e.g. .NET Remoting, Web Service, ...) to wrapper your code for external access.

    HttpWebRequest method is not be recommended, Web Service interface is best method.

    2006年11月27日 上午 08:41
    版主

所有回覆

  • no body help me?
    2006年11月27日 上午 01:07
  • How can I help you ?

    Your post cannot be understandard.

    Please see the function and path for your requirements from Windows SharePoint Service SDK.
    I recommend you to use Web Service method, not HttpWebRequest.

    2006年11月27日 上午 05:24
    版主
  • Thanks for you reply.

    Can the SDK of WSS work in a distributed environment? I have codes work locally, but don't find way to work in a dist environment. For example: SPSite site = new SPSite(url) can only work locally, that's why i try to use httprequest.

    2006年11月27日 上午 07:54
  • I think it's OK for work.

    But, you must use WSS's Web Service interface to do your needs, and, your code might change for WSS Web Service interactions.

    If you want to call WSS managed library directly, please implement a middle component (e.g. .NET Remoting, Web Service, ...) to wrapper your code for external access.

    HttpWebRequest method is not be recommended, Web Service interface is best method.

    2006年11月27日 上午 08:41
    版主
  • Thanks, I had work it out through web service.

    Thanks for you kind help.

    2006年12月1日 上午 06:26