2012-09-14 5 views
0

다른 서버에있는 문서 라이브러리에서 문서를 다운로드하기 위해 list.asmx (getlistitems 메서드)를 사용하여 Windows 응용 프로그램을 만들었습니다. 문서 이름, URL 등에 액세스 할 수 있습니다. 다음 코드를 사용하여 파일을 다운로드하면 다운로드하려는 각 파일의 내용으로 로그인 페이지의 HTML이 반환됩니다.GetListitems가 예상 결과를 반환하지 않음

의견이 있으십니까?

  Dim spAuthentication As New Authentication() 
      spAuthentication.Url = authenticationWSAddress 
      spAuthentication.CookieContainer = New CookieContainer() 
      Dim spLists As New Lists() 
      spLists.Url = listWSAddress 
      'Try to login to SharePoint site with Form based authentication 
      Dim loginResult As LoginResult = spAuthentication.Login(userName, password) 
      Dim cookie As New Cookie() 
      'If login is successfull 
      If loginResult.ErrorCode = LoginErrorCode.NoError Then 
       'Get the cookie collection from the authenticatin web service 
       Dim cookies As CookieCollection = spAuthentication.CookieContainer.GetCookies(New Uri(spAuthentication.Url)) 
       'Get the specific cookie which contains the security token 

       cookie = cookies(loginResult.CookieName) 
       'Initialize the cookie container of the list web service 
       spLists.CookieContainer = New CookieContainer() 
       'set the cookie of list web service to the authenticatio cookie 
       spLists.CookieContainer.Add(cookie) 
       'Dim responseNode As XmlNode = spLists.GetListCollection() 
       'response = responseNode.InnerXml 

       Dim query As String = "<mylistitems><Query><Where><Eq><FieldRef Name='FileDirRef' /><Value Type='Url'>DocLib/Property Documents/BELASERA AT FULTON (lax10027)/Master Meter Invoices</Value></Eq></Where></Query><QueryOptions><ViewAttributes Scope='RecursiveAll' IncludeRootFolder='False' /><IncludeAttachmentUrls>TRUE</IncludeAttachmentUrls><ViewFields><FieldRef Name='EncodedAbsUrl'/></ViewFields></QueryOptions></mylistitems>" 
       Dim doc As New XmlDocument() 
       doc.LoadXml(query) 
       Dim dt As DataTable = Nothing 
       Dim queryNode As XmlNode = doc.SelectSingleNode("//Query") 
       Dim viewNode As XmlNode = doc.SelectSingleNode("//ViewFields") 
       Dim optionNode As XmlNode = doc.SelectSingleNode("//QueryOptions") 

       Dim retNode As XmlNode = spLists.GetListItems("DocLib", String.Empty, queryNode, viewNode, String.Empty, optionNode, Nothing) 

       Dim ds As New DataSet() 
       Using sr As New StringReader(retNode.OuterXml) 
        ds.ReadXml(sr) 
       End Using 

       If ds.Tables("Row") IsNot Nothing AndAlso ds.Tables("Row").Rows.Count > 0 Then 
        dt = ds.Tables("Row").Copy() 
        For Each myrow As DataRow In dt.Rows 
         ' myrow.Item(0) contains url of the document 
         If myrow.Item(0) IsNot Nothing AndAlso myrow.Item(0) <> "" Then 
          DownLoadAttachmentold(myrow.Item("ows_EncodedAbsUrl"), RemoveLookupID(myrow.Item("ows_FileLeafRef"))) 
         End If 
        Next 
       End If 




    Public Shared Sub DownLoadAttachment(ByVal strURL As String, ByVal strFileName As String) 
     Dim myWebClient As New WebClient() 
     Dim DestinationFolder As String = "C:\\DownLoads\\" 
     Form2.RTBStatus.AppendText("Downloading File " + strFileName + " from " + strURL + " .......") 
     ' The DownloadFile() method downloads the Web resource and saves it into the current file-system folder. 
     myWebClient.DownloadFile(strURL, DestinationFolder + strFileName) 
     'Form2.RTBStatus.AppendText("Successfully Downloaded file ""{0}"" from ""{1}""", "C:\\DownLoads\\" + strFileName, strURL) 
     Form2.RTBStatus.AppendText((ControlChars.Cr + "Downloaded file saved in the following file system folder:" + ControlChars.Cr + ControlChars.Tab + DestinationFolder)) 

    End Sub 
+0

셰어 2,007 ??? –

답변

0

DownloadAttachment는 (양식 기반의) 인증 된 HTTP 요청도 만들어야합니다.

이하 C에서 # 예 :

request = (HttpWebRequest)WebRequest.Create(strURL); 
request.Credentials = System.Net.CredentialCache.DefaultCredentials;//adapt for your FBA 
request.AllowWriteStreamBuffering = false; 
response = (HttpWebResponse)request.GetResponse(); 
Stream s = response.GetResponseStream(); 
FileStream fs = new FileStream(@"C:\DownLoads\"+strFileName, FileMode.Create); 
관련 문제