2013-07-03 333 views
0

我試圖通過Vbscript創建文件夾。Vbscript webdav文件夾創建

我很喜歡Vbscript。

無法理解這段代碼爲什麼返回:該文件夾尚未創建。狀態是不支持的媒體類型。

我把它在這裏http://blogs.msdn.com/b/webdav_101/archive/2008/03/12/howto-vb-an-example-to-create-a-public-folder-with-storage-limit-settings.aspx

代碼[VBScript中]:

cmdMakeFolder_Click 

Private Sub cmdMakeFolder_Click() 
    Dim XMLreq 
    Set XMLreq = createobject("MSXML2.XMLHTTP.3.0") 
    Dim sReq 
    Dim parsePhone 
    Dim sSourceURL 

    sSourceURL = "https://shkur.webdav.hidrive.strato.com/users/shkur/" 
    ' Note: This URL is broken down as: 
    '  myexserver is the Exchange box name 
    '  MYDOM.EXTEST.MYCOMP.COM is the full domain name the Exchange box is in. 
    '  Exadmin/admin is a special designation giving the login user higher level privs. 
    ' Exchange explorer may/may not need the %20 in PUBLIC%20FOLDERS 
    ' The account you use to log in with Must have full blown Exchange admin privs and be 
    ' a domain acct. 

    'XMLreq.open "MKCOL", sSourceURL, False, "Administrator", "Pxxxx" 
      ' If the Exchange is the DC, you probably dont have to specify the DC to login 
    XMLreq.open "MKCOL", sSourceURL, False, "login", "password" 
      ' Here Exchange box is not the DC 

    XMLreq.setRequestHeader "Content-Type", "text/xml" 

    sReq = "<?xml version='1.0'?>" 
    sReq = sReq & "<a:propertyupdate xmlns:a='DAV:' xmlns:e='http://schemas.microsoft.com/exchange/' " & _ 
        "xmlns:p='http://schemas.microsoft.com/mapi/proptag/'>" 
    sReq = sReq & "<a:set><a:prop>" & vbCrLf 
    sReq = sReq & "<e:outlookfolderclass>IPF.Folder</e:outlookfolderclass>" & vbCrLf  
      ' Folder class for outlook 
    sReq = sReq & "<a:contentclass>urn:content-classes:folder</a:contentclass>" & vbCrLf 
      ' Folder content class 
    sReq = sReq & "<a:isreadonly>1</a:isreadonly>" & vbCrLf ' Read only 
    sReq = sReq & "<a:ishidden>1</a:ishidden>" & vbCrLf  ' Hidden 

    sReq = sReq & "<p:x67790003>1</p:x67790003>" & vbCrLf 
      'Use the quotas specified by other properties. 
    sReq = sReq & "<e:storagequotaissuewarninglimit>200</e:storagequotaissuewarninglimit>" & vbCrLf 
      'Issue warning at (Kb). 
    sReq = sReq & "<p:x67210003>1</p:x67210003>" & vbCrLf 'Prohibit post at (Kb). 
    sReq = sReq & "<p:x67220003>1</p:x67220003>" & vbCrLf 'Maximum item size (Kb). 

    sReq = sReq & "<e:addressbookdisplayname>qwe</e:addressbookdisplayname>" & vbCrLf 

    sReq = sReq & "</a:prop></a:set></a:propertyupdate>" 

    XMLreq.send sReq 
    'Debug.Print "xmlReq.Status = " & XMLreq.Status 
    If XMLreq.Status = "201" Or XMLreq.Status = "207" Then 
     MsgBox "The folder has been created. Status is " & XMLreq.statusText, vbCritical, "Folder Created!!" 
    Else 
     ' Note: Error 405 can mean permissions problem on item already exists. 
     MsgBox "The folder has not been created. Status is " & XMLreq.statusText, vbCritical, " Folder not Created!!" 
    End If 
End Sub 

回答

2

這響應狀態(415 - 不支持的媒體類型)表示服務器拒絕請求的實體。在您的請求中,請求實體是XML。請注意,「正常」的MKCOL請求不會在主體中使用XML,只有擴展的MKCOL纔會這樣做,這並不會影響所有服務器。

因此,它最有可能只是您使用的是不支持擴展的MKCOL WebDAV服務器

http://tools.ietf.org/html/draft-ietf-vcarddav-webdav-mkcol-06

+0

http://greenbytes.de/tech/webdav/rfc5689.html,實際上。 –

0

отвечаюсамсебевоттакработает!

cmdMakeFolder_Click 

Private Sub cmdMakeFolder_Click() 
    Dim XMLreq 
    Set XMLreq = createobject("MSXML2.XMLHTTP.3.0") 
    'Set XMLreq = createobject("MSXML2.XMLHTTP.4.0") 
    Dim sReq 
    Dim parsePhone 
    Dim sSourceURL 

    sSourceURL = "https://shkur.webdav.hidrive.strato.com/users/shkur/qweer/" 
    ' Note: This URL is broken down as: 
    '  myexserver is the Exchange box name 
    '  MYDOM.EXTEST.MYCOMP.COM is the full domain name the Exchange box is in. 
    '  Exadmin/admin is a special designation giving the login user higher level privs. 
    ' Exchange explorer may/may not need the %20 in PUBLIC%20FOLDERS 
    ' The account you use to log in with Must have full blown Exchange admin privs and be 
    ' a domain acct. 

    'XMLreq.open "MKCOL", sSourceURL, False, "Administrator", "Pxxxx" 
      ' If the Exchange is the DC, you probably dont have to specify the DC to login 
    XMLreq.open "MKCOL", sSourceURL, False, "login", "password" 
      ' Here Exchange box is not the DC 

    XMLreq.setRequestHeader "Content-Type", "text/xml" 

    'sReq = "<?xml version='1.0'?><a:propertyupdate xmlns:a='DAV:' xmlns:e='http://schemas.microsoft.com/exchange/' xmlns:p='http://schemas.microsoft.com/mapi/proptag/'><a:set><a:prop><e:outlookfolderclass>IPF.Folder</e:outlookfolderclass><a:contentclass>urn:content-classes:folder</a:contentclass><a:isreadonly>1</a:isreadonly><a:ishidden>1</a:ishidden><p:x67790003>1</p:x67790003><e:storagequotaissuewarninglimit>200</e:storagequotaissuewarninglimit><p:x67210003>1</p:x67210003><p:x67220003>1</p:x67220003><e:addressbookdisplayname>qwe</e:addressbookdisplayname></a:prop></a:set></a:propertyupdate>" 

    XMLreq.send sReq 
    'Debug.Print "xmlReq.Status = " & XMLreq.Status 
    If XMLreq.Status = "201" Or XMLreq.Status = "207" Then 
     MsgBox "The folder has been created. Status is " & XMLreq.statusText, vbCritical, "Folder Created!!" 
    Else 
     ' Note: Error 405 can mean permissions problem on item already exists. 
     MsgBox "The folder has not been created. Status is " & XMLreq.statusText, vbCritical, " Folder not Created!!" 
    End If 
End Sub 
0

看來你試圖使用MKCOL(微軟專用)的非標準擴展與一個不理解它的服務器。