簡體   English   中英

如何使用Asp.net在Sharepoint中創建文件

[英]How to create a file in sharepoint using asp.net

我正在編寫代碼以彈出窗口,一旦用戶完成內容和標題的編寫,它將創建一個.aspx文件並上傳到文檔庫。

但是我該怎么辦呢? 我用谷歌搜索,但資料不多!

有人可以幫忙嗎?

您需要使用“客戶端對象模型”。 您可以參閱(http://www.codeproject.com/Articles/268193/SharePoint-2010-Client-Object-Model-Part-1)以了解客戶端對象模型的基本知識。 您需要在庫中創建文件的代碼是:

 String fileToUpload = @"C:\YourFile.txt";
        String sharePointSite = "http://yoursite.com/sites/Research/";
        String documentLibraryName = "Shared Documents";

        using (SPSite oSite = new SPSite(sharePointSite))
        {
            using (SPWeb oWeb = oSite.OpenWeb())
            {
                if (!System.IO.File.Exists(fileToUpload))
                    throw new FileNotFoundException("File not found.", fileToUpload);                    

                SPFolder myLibrary = oWeb.Folders[documentLibraryName];

                // Prepare to upload
                Boolean replaceExistingFiles = true;
                String fileName = System.IO.Path.GetFileName(fileToUpload);
                FileStream fileStream = File.OpenRead(fileToUpload);

                // Upload document
                SPFile spfile = myLibrary.Files.Add(fileName, fileStream, replaceExistingFiles);

                // Commit 
                myLibrary.Update();
            }
        }

暫無
暫無

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

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