无法获取列表项的作者登录名 [英] Can't get list item's author loginname
本文介绍了无法获取列表项的作者登录名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此代码:
using(var clientContext = new ClientContext(url))
{
WebClient webClient = new WebClient();
网站siteCollection = clientContext.Site;
网站= clientContext.Web;
clientContext.Load(site);
ListCollection availableLists = site.Lists;
clientContext.Load(availableLists);
clientContext.ExecuteQuery();
foreach(可用列表中的列表列表)
{
列表listToSearch = clientContext.Web.Lists.GetByTitle(list.Title);
clientContext.Load(listToSearch);
clientContext.ExecuteQuery();
var sourceList = clientContext.Web.Lists.GetByTitle(list.Title);
var qry = new CamlQuery();
qry.ViewXml ="< View Scope ='RecursiveAll'>" +
"< Query>" +
"< Where>" +
"< Eq>" +
"< FieldRef Name ='FSObjType'/>" +
"< Value Type ='Integer'> 0< / Value>" +
"< / Eq>" +
"< / Where>" +
"< / Query>" +
"< / View>" ;;
var listItems = sourceList.GetItems(qry);
clientContext.Load(listItems);
clientContext.ExecuteQuery();
foreach(listItems中的var listItem)
{
var fileRef =(string)listItem [" FileRef"];
var fileName = Path.GetFileName(fileRef);
MessageBox.Show(listItem.IsPropertyAvailable(" Modified_x0020_By")。ToString());
var fileUrl =(Path.GetFullPath(fileRef))。替换("C:\\",""")。替换("c:\\" ;,"")。替换("\\","" /");
if(fileUrl.ToLower()。StartsWith(" boa /"))
{
fileUrl =" https://www.test.com/" ; + fileUrl;
}
其他
{
fileUrl =" https://www.test2.com/" + fileUrl;
}
try
{
string downloadedFileName = fileUrl.Substring(fileUrl.LastIndexOf('/')+ 1);
string downloadedFileExtenstion = fileUrl.Substring(fileUrl.LastIndexOf('。')+ 1);
downloadedFileName = downloadedFileName.Replace("。" + downloadedFileExtenstion,"");
string downloadedFileSiteUrl = fileUrl.Remove(fileUrl.LastIndexOf('/'));
if(!(downloadedFileName.ToLower()。包含(&.; master")))
{
/ *
uploadProgressBar.Value = 0;
for(int i = 1; i< = 100; i ++)
{
//等待100毫秒。
Thread.Sleep(100);
//报告进度。
uploadProgressBar.Value = i;
}
* /
//下载并保存文件开始
HttpWebRequest请求;
HttpWebResponse response = null;
request =(HttpWebRequest)WebRequest.Create(fileUrl);
request.Credentials = CredentialCache.DefaultCredentials;
request.Timeout = 10000;
request.AllowWriteStreamBuffering = false;
response =(HttpWebResponse)request.GetResponse();
Stream s = response.GetResponseStream();
//写入磁盘
if(!Directory.Exists(" C:\\Temp\\NDI\\"))
{
Directory.CreateDirectory(" C:\\Temp \\NDI \\');
}
string aFilePath =" C:\\Temp \\NDI \\" + downloadedFileName +"。" + downloadedFileExtenstion;
FileStream fs = new FileStream(aFilePath,FileMode.Create);
byte [] read = new byte [256];
int count = s.Read(read,0,read.Length);
while(count> 0)
{
fs.Write(read,0,count);
count = s.Read(read,0,read.Length);
}
fs.Close();
s.Close();
//将数据传递给DataTable进行CSV启动
if(csvCount == 0)
{
addToCsv(0,"", "","","","");
csvCount ++;
}
else
{
addToCsv(csvCount,downloadedFileSiteUrl,downloadedFileName,downloadedFileExtenstion,clientNumber,matterNumber);
}
//将数据传递给DataTable用于CSV结束
string selectedCabinetId =(listOfCurrentCabinets.SelectedItem as ComboboxItem).Value.ToString();
uploadFileToNetdocs(aFilePath,downloadedFileName,downloadedFileExtenstion,clientNumber,matterNumber,selectedCabinetId);
//MessageBox.Show("FILE DONE DOWNLOADING!");
deleteFile(aFilePath);
response.Close();
//下载并保存文件结束
//MessageBox.Show(fileUrl +" |" + downloadedFileName);
//MessageBox.Show(fileUrl);
// uploadFileToNetdocs(" File Location",downloadedFileName,downloadedFileExtenstion)
}
}
catch {}
}
}
}
但我似乎无法获得该项目的作者或作者登录名。有什么建议吗?
解决方案
嘿
我看不到你的代码来获取作者
I am using this code:
using (var clientContext = new ClientContext(url)) { WebClient webClient = new WebClient(); Site siteCollection = clientContext.Site; Web site = clientContext.Web; clientContext.Load(site); ListCollection availableLists = site.Lists; clientContext.Load(availableLists); clientContext.ExecuteQuery(); foreach (List list in availableLists) { List listToSearch = clientContext.Web.Lists.GetByTitle(list.Title); clientContext.Load(listToSearch); clientContext.ExecuteQuery(); var sourceList = clientContext.Web.Lists.GetByTitle(list.Title); var qry = new CamlQuery(); qry.ViewXml = "<View Scope='RecursiveAll'>" + "<Query>" + "<Where>" + "<Eq>" + "<FieldRef Name='FSObjType' />" + "<Value Type='Integer'>0</Value>" + "</Eq>" + "</Where>" + "</Query>" + "</View>"; var listItems = sourceList.GetItems(qry); clientContext.Load(listItems); clientContext.ExecuteQuery(); foreach (var listItem in listItems) { var fileRef = (string)listItem["FileRef"]; var fileName = Path.GetFileName(fileRef); MessageBox.Show(listItem.IsPropertyAvailable("Modified_x0020_By").ToString()); var fileUrl = (Path.GetFullPath(fileRef)).Replace("C:\\", "").Replace("c:\\", "").Replace("\\", "/"); if (fileUrl.ToLower().StartsWith("boa/")) { fileUrl = "https://www.test.com/" + fileUrl; } else { fileUrl = "https://www.test2.com/" + fileUrl; } try { string downloadedFileName = fileUrl.Substring(fileUrl.LastIndexOf('/') + 1); string downloadedFileExtenstion = fileUrl.Substring(fileUrl.LastIndexOf('.') + 1); downloadedFileName = downloadedFileName.Replace("." + downloadedFileExtenstion, ""); string downloadedFileSiteUrl = fileUrl.Remove(fileUrl.LastIndexOf('/')); if (!(downloadedFileName.ToLower().Contains(".master"))) { /* uploadProgressBar.Value = 0; for (int i = 1; i <= 100; i++) { // Wait 100 milliseconds. Thread.Sleep(100); // Report progress. uploadProgressBar.Value = i; } */ //Download and Save File Start HttpWebRequest request; HttpWebResponse response = null; request = (HttpWebRequest)WebRequest.Create(fileUrl); request.Credentials = CredentialCache.DefaultCredentials; request.Timeout = 10000; request.AllowWriteStreamBuffering = false; response = (HttpWebResponse)request.GetResponse(); Stream s = response.GetResponseStream(); // Write to disk if (!Directory.Exists("C:\\Temp\\NDI\\")) { Directory.CreateDirectory("C:\\Temp\\NDI\\"); } string aFilePath = "C:\\Temp\\NDI\\" + downloadedFileName + "." + downloadedFileExtenstion; FileStream fs = new FileStream(aFilePath, FileMode.Create); byte[] read = new byte[256]; int count = s.Read(read, 0, read.Length); while (count > 0) { fs.Write(read, 0, count); count = s.Read(read, 0, read.Length); } fs.Close(); s.Close(); //Pass Data To DataTable For CSV Start if (csvCount == 0) { addToCsv(0, "", "", "", "", ""); csvCount++; } else { addToCsv(csvCount, downloadedFileSiteUrl, downloadedFileName, downloadedFileExtenstion, clientNumber, matterNumber); } //Pass Data To DataTable For CSV End string selectedCabinetId = (listOfCurrentCabinets.SelectedItem as ComboboxItem).Value.ToString(); uploadFileToNetdocs(aFilePath, downloadedFileName, downloadedFileExtenstion, clientNumber, matterNumber, selectedCabinetId); //MessageBox.Show("FILE DONE DOWNLOADING!"); deleteFile(aFilePath); response.Close(); //Download and Save File End //MessageBox.Show(fileUrl + " | " + downloadedFileName); //MessageBox.Show(fileUrl); //uploadFileToNetdocs("File Location", downloadedFileName, downloadedFileExtenstion) } } catch { } } } }
But I cannot seem to get the Author or the author loginname for the item. Any suggestions?
解决方案
Hey
I don't see your code to get the Author.
这篇关于无法获取列表项的作者登录名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文