如何将XML文件下载到XML文件的早期版本 [英] How to Download to XML files Previous Versions of Infopath form SharePoint

查看:115
本文介绍了如何将XML文件下载到XML文件的早期版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我访问Infopath文件列表时,例如选择一个文件并单击版本历史记录",是否可以在不恢复旧版本的情况下下载以前的版本?

When i access the list of Infopath files, and select one for example and click the Version History, is there a way to download previous versions without Restoring the old versions?

推荐答案

这仅适用于库中的项目(不适用于列表).需要记住的几点:

This will only work for items in libraries (and wont work on lists). Some points to remember:

  • 库具有称为文件的属性
  • 文件具有称为版本的属性
  • 版本具有一个称为Url的属性

请牢记这三个,可以通过执行以下操作为InfoPath文件的所有版本历史记录提取下载URL:

With those three in mind, you can pull the download URL for all the version history of the InfoPath file by doing the following:

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的方法?这是一个简单的方法,仅获取文档的主要版本号.看起来像这样:

Notice that I used a method called GetVersion? This is a simple method which just gets the major version # of a document. It looks like this:

public static int GetVersion(string itemVersion)
    {
        int index = itemVersion.IndexOf('.');
        return int.Parse(itemVersion.Substring(0, index));
    }

如果您需要次要版本,则可以创建另一种方法来提取该信息.此方法的用途是生成每个文档版本所需的下载链接.至于为什么需要将版本增加到512的详细信息,可以在

If you will be needing the minor version you can just create another method to pull that information. What this method is used for is to generate the download link you need for each document version. As for the details on why we need to multiply the version to 512, you can read it up on here.

希望这会有所帮助. :)

Hope this helps. :)

这篇关于如何将XML文件下载到XML文件的早期版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆