簡體   English   中英

使用asp.net將文檔上傳到sharepoint

[英]Document Upload into sharepoint using asp.net

我有一個具有formview的表單。 我想包含一個fileupload控件,用於將文件上傳到sharepoint存儲庫中,並將上傳的文件另存為ID_1,ID_2等。我是asp.net的新手。 我需要有關如何執行此操作的幫助

您可以使用客戶端對象模型將文件上傳到共享點:

public void UploadFileToSharePoint(string filePath)
{
        ClientContext context = new ClientContext("yoursite");
        Web web = context.Web;

        FileCreationInformation newFile = new FileCreationInformation();
        newFile.Content = System.IO.File.ReadAllBytes(filePath);
        newFile.Url = System.IO.Path.GetFileName(filePath);

        List docs = web.Lists.GetByTitle("LibName");
        Microsoft.SharePoint.Client.File uploadFile = docs.RootFolder.Files.Add(newFile);

        context.Load(uploadFile);

        context.ExecuteQuery();
}

之后,您可以使用所需的ID更新列表項,或者可以附加項目更新事件處理程序來更新文件的標題。

  private static void UploadBtn_click(Object sender, EventArgs e)
  {  
   using (SPSite osite = new SPSite("URL"))
   {
    using (SPWeb oWeb = osite.OpenWeb())
    {
    oWeb.AllowUnsafeUpdates = true;
    SPList list = oWeb.TryGetList("ListName");
    SPListItem item = list.AddItem();
    FileStream stream = new FileStream(UploadBtn.FileName, FileMode.Open) ;
    byte[] byteArray = new byte[stream.Length];
    stream.Read(byteArray, 0, Convert.ToInt32(stream.Length));
    stream.Close();

    //read Last item ID here refer my 2nd link bellow

    item.Attachments.Add("ID_1.doc", byteArray);
    item["Title"] = TextBox1.Text;
    item.Update();
    oWeb.AllowUnsafeUpdates = false;
   }
  }
}

上傳的一種方法1) http://msdn.microsoft.com/zh-cn/library/lists.lists.addattachment.aspx

2) 獲取Sharepoint列表中的第一個和最后一個ListItem

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM