2009-10-08 2 views
0

나는 Sharepoint에있는 요소들의 목록을 가지고있다. 제목, 설명, 첨부 옵션이있다. 고전적인 목록입니다.Sharepoint, 다운로드하지 않고 첨부 파일의 킬로바이트를 아는 방법?

첨부 파일의 킬로바이트를 표시하는 모든 항목의 목록을 만들어야합니다. http://example.com/../attachments/delete.txt

얻을 수있는 파일을 다운로드 나를 강제로 WebRequest 클래스를하지 않고 내가 KBS를 알 수있는 방법 :

문제는 내가 알고있는 유일한 경로가 URI 경로이기 때문에 내가하는에서는 FileInfo을 할 수 있다는 것입니다 이 정보.

답변

1

보통 머리글 만 가져오고 응답의 Content-Length 헤더를 보는 HEAD 요청을 만들어 일반 URI에서 파일 크기를 가져올 수 있습니다.

System.Net.WebRequest req = System.Net.HttpWebRequest.Create("https://stackoverflow.com/robots.txt"); 
req.Method = "HEAD"; 
System.Net.WebResponse resp = req.GetResponse(); 
int ContentLength; 
if(int.TryParse(resp.Headers.Get("Content-Length"), out ContentLength)) 
{ 
    //Do something useful with ContentLength here 
} 

(code from this stackoverflow question)

+0

, 당신은 여기에 대한 세부 사항을 포함하지 않았다. 검색 대상 웹 서버와 파일 시스템을 제어하는 ​​경우이 작업을 수행하는 더 쉬운 방법이 있습니다. –

3

하는이 시도 :이 대상 웹 서버는 물론 구성 방법에 따라 달라집니다

using (SPSite site = new SPSite("http://fsm/Lists/sample/AllItems.aspx")) 
{ 
    using (SPWeb web = site.OpenWeb()) 
    { 
     SPList list = web.Lists["sample"]; 
     SPListItemCollection items = list.GetItems(new SPQuery()); 
     foreach (SPListItem item in items) 
     { 
      foreach (string attachment in item.Attachments) 
      { 
       // "http://fsm" + "Lists/sample/1_.000" 
       Uri itemAddress = new Uri(new Uri(web.Url), item.Url); 
       Uri attachmentAddress = new Uri(itemAddress, 
        String.Format("Attachments/{0}/{1}", item.ID, attachment)); 
       SPFile file = web.GetFile(attachmentAddress.AbsoluteUri); 
       Console.WriteLine("{0} have {1} bytes", file.Name, file.Length); 
      } 
     } 
    } 
} 
+0

정보를 보내 주셔서 감사하지만 SPDocumentLibrary의 파일이 아니며 검색 할 수있는 listitem의 첨부 파일입니다 with : SPAttachmentCollection attachs = items [0] .Attachments; 아이디어가 있으십니까? – netadictos

+2

web.GetFile (item.Attachments [0])은 어떨까요? Length? –

+0

그러면 이름 파일의 문자 길이가 제공됩니다. – netadictos

관련 문제