信息路径表格 [英] Infopath form

查看:79
本文介绍了信息路径表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将xml infopath表单作为文档添加到了对用户不起作用的文档库中.如何将xml Infopath表单作为文档添加到文档库中?我已经将表单添加到表单库中,但是不知道如何传输文档 从表单库到文档库.该文档库还具有其他pdf格式,word和excel格式,这些格式对于用户来说很好用.我对SP开发非常陌生.谢谢.

I added an xml infopath form as a document to a document library which does not work for the user.How can I add an xml Infopath form as a document to a document library? I have already added the form to the form library but don't know how to transfer a document from the form library to a document library either. This document library has other pdf forms, word and excel forms which work fine for the user. I am extremely new to the SP development. Thank you.


推荐答案

您可以直接将xml文件上传到文档库中.

You can upload the xml file to document library directly.

如果您想通过Code来实现,请参考以下CSOM的简单演示.

If you want to achieve this by Code, here is a simple demo of CSOM for your reference.

    class Program
    {
        static void Main(string[] args)
        {
            string siteURL = "http://sp/sites/DevSite";
            CopyDocFromOneListToAnother(siteURL, "http://sp", "TestForm", "MyDocLib", "Test1.xml");
            Console.WriteLine("success");
            Console.ReadLine();
                                                                  
        }

        /// <summary>
        /// copy a file from a document library to another document library
        /// </summary>
        /// <param name="siteUrl"></param>
        /// <param name="host"></param>
        /// <param name="sourceListName"></param>
        /// <param name="destinationListName"></param>
        public static void CopyDocFromOneListToAnother(string siteUrl, string host, string sourceListName, string destinationListName, string fileName)
        {
            siteUrl = siteUrl.EndsWith("/") ? siteUrl.Substring(0, siteUrl.Length - 1) : siteUrl;
            ClientContext context = new ClientContext(siteUrl);
            Web web = context.Site.RootWeb;

            List source = web.Lists.GetByTitle(sourceListName);
            List destination = web.Lists.GetByTitle(destinationListName);
            context.Load(source);
            context.Load(destination);
            context.Load(web);
            context.ExecuteQuery();

            FileCollection files = source.RootFolder.Files;
            Microsoft.SharePoint.Client.File file = files.GetByUrl(siteUrl+"/"+sourceListName+"/"+fileName);
            context.Load(file);
            context.ExecuteQuery();
            
                FileInformation fileInfo = Microsoft.SharePoint.Client.File.OpenBinaryDirect(context, file.ServerRelativeUrl);
                string filePath = host + file.ServerRelativeUrl;
                System.IO.Stream fileStream = fileInfo.Stream;
                FileCreationInformation createFile = new FileCreationInformation();
                byte[] bufferByte = new byte[1024 * 100];
                System.IO.MemoryStream memory = new System.IO.MemoryStream();
                int len = 0;
                while ((len = fileStream.Read(bufferByte, 0, bufferByte.Length)) > 0)
                {
                    memory.Write(bufferByte, 0, len);
                }
                byte[] bytes = memory.GetBuffer();

                createFile.Content = bytes;
                createFile.Url = siteUrl + "/" + destinationListName + "/" + file.Name;
                createFile.Overwrite = true;
                Microsoft.SharePoint.Client.File newFile = destination.RootFolder.Files.Add(createFile);
                newFile.ListItemAllFields.Update();
                context.ExecuteQuery();
           
        }
}

结果截图:

最诚挚的问候,

刘李


这篇关于信息路径表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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