当我访问Infopath文件列表并选择一个例如并单击版本历史记录时,有没有办法下载以前的版本而无需恢复旧版本?
答案 0 :(得分:0)
这仅适用于库中的项目(并且不适用于列表)。要记住一些要点:
考虑到这三点,您可以通过执行以下操作来提取InfoPath文件的所有版本历史记录的下载URL:
public static void Main(string[] args)
{
ClientContext context = new ClientContext(<sharepoint site here>);
Web site = context.Web;
List docLib = site.Lists.GetByTitle(<doc lib here>);
context.Load(docLib);
CamlQuery caml = new CamlQuery();
ListItemCollection items = docLib.GetItems(caml);
context.Load(items);
context.ExecuteQuery();
Console.WriteLine("Pulling information...");
foreach(ListItem item in items)
{
//You can change title to any internal field name that you want to use as basis
if (item.FieldValues["Title"] != null)
{
Console.WriteLine("File Name: " + item.FieldValues["Title"]);
context.Load(item);
//this gets ALL the version of the file
FileVersionCollection versions = item.File.Versions;
context.Load(versions);
context.ExecuteQuery();
if (versions != null)
{
foreach (FileVersion version in versions)
{
User usr = version.CreatedBy as User;
context.Load(usr);
context.ExecuteQuery();
//will be explained in detail
int ver = GetVersion(version.VersionLabel);
//will be explained in detail
int verLink = ver * 512;
string link = "your sharepoint site";
//Console.WriteLine("Version Info:: {0}, {1}, {2}, {3}", version.VersionLabel, version.Created, usr.LoginName, version.CheckInComment);
Console.WriteLine("Document Link: " + link + version.Url);
Console.WriteLine("Version: " + ver.ToString());
Console.WriteLine("Created: " + version.Created);
Console.WriteLine("Created By: " + usr.LoginName);
Console.WriteLine("Comments: " + version.CheckInComment);
}
}
}
}
Console.WriteLine("Pulling information complete.");
Console.Read();
}
请注意,我使用了一个名为GetVersion
的方法?这是一个简单的方法,它只获取文档的主要版本#。它看起来像这样:
public static int GetVersion(string itemVersion)
{
int index = itemVersion.IndexOf('.');
return int.Parse(itemVersion.Substring(0, index));
}
如果您需要次要版本,您可以创建另一种方法来提取该信息。此方法的用途是生成每个文档版本所需的下载链接。至于我们为什么需要将版本乘以512的详细信息,您可以在here上阅读。
希望这会有所帮助。 :)