![]() ![]() ![]() ![]() |
|||||
|
|||||
樓主 大雄 ![]()
![]() |
小弟目前以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 |