台灣最大程式設計社群網站
線上人數
1367
 
會員總數:246690
討論主題:190103
歡迎您免費加入會員
討論區列表 >> C# >> c# SharePoint 應用疑問
[]  
[我要回覆]
回應主題 加入我的關注話題 檢舉此篇討論 將提問者加入個人黑名單
c# SharePoint 應用疑問
價值 : 50 QP  點閱數:843 回應數:0
樓主

大雄
門外漢
0 51
843 59
發送站內信

請問各位前輩:

小弟目前以c#在開發SharePoint的相關應用,在試搬檔案功能時有些問題出現,想請教各位前輩

小弟的程式碼如下

private void MoveFile()
{
Configuration config = WebConfigurationManager.OpenWebConfiguration(this.Request.ApplicationPath);
AppSettingsSection myAppSettingsSection = (AppSettingsSection)config.GetSection("appSettings");
String UserName = myAppSettingsSection.Settings["UserName"].Value;
String PassWord = myAppSettingsSection.Settings["PassWord"].Value;
String Domain = myAppSettingsSection.Settings["Domain"].Value;

ClientContext clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new NetworkCredential(UserName, PassWord, Domain);
clientContext.Load(clientContext.Web);

List list = clientContext.Web.Lists.GetByTitle("文件");
clientContext.Load(list);
clientContext.ExecuteQuery();
string fileUrl = "http://sps.tcbadtest.com.tw/IT";
using (var ctx = new ClientContext"http://testspsite/IT"))
{
ctx.Credentials = clientContext.Credentials;
}

var targetSite = new Uri("http://sps.tcbadtest.com.tw/IT");
string src = @"/IT/Shared Documents/test";
string dest = @"IT/Shared Documents/test/subfolder1";
string lst = "文件";

MoveFiles(targetSite, lst, src, dest,clientContext);

}

public void MoveFiles(Uri url, string listTitle, string srcFolder, string destFolder, ClientContext clientContext)
{
using (var context = new ClientContext(url))
{
context.Credentials = clientContext.Credentials;
List srcList = context.Web.Lists.GetByTitle(listTitle);
context.Load(srcList);
context.ExecuteQuery();

var qry = CamlQuery.CreateAllItemsQuery();
qry.FolderServerRelativeUrl = srcFolder;
var srcItems = srcList.GetItems(qry);
context.Load(srcItems, icol => icol.Include
(i => i.FileSystemObjectType,
i => i.File));
context.ExecuteQuery();

foreach (var item in srcItems)
{
if (item.FileSystemObjectType == FileSystemObjectType.File)
{
var destFileUrl = string.Format("{0}/{1}/{2}", item, destFolder, item.File.Name);
//Label6.Text += destFileUrl;
item.File.MoveTo(destFileUrl, MoveOperations.Overwrite);
context.ExecuteQuery();
}
}
}
}

小弟打算把/IT/Shared Documents/test底下的檔案搬到 IT/Shared Documents/test/subfolder1下,可是執行後卻會出現找不到subfolder1,小弟已經確認過該資料夾是存在的,請問是程式哪裡有問題嗎??

搜尋相關Tags的文章: [ SharePoint ] ,
本篇文章發表於2017-08-23 14:23
目前尚無任何回覆
   

回覆
如要回應,請先登入.