不同机器上的多个用户是否可以通过C# WinForm程序将表单输入写入SharePoint上的同一Excel文件?
创始人
2025-01-09 05:30:16
0

是的,可以通过C# WinForm程序将表单输入写入SharePoint上的同一Excel文件。下面是一个示例代码:

using Microsoft.SharePoint.Client;
using Microsoft.SharePoint.Client.Utilities;
using System;
using System.IO;
using System.Windows.Forms;

namespace SharePointExcelWriter
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnSubmit_Click(object sender, EventArgs e)
        {
            // SharePoint网站URL
            string siteUrl = "https://your-sharepoint-site-url";

            // SharePoint文档库名称
            string libraryName = "Documents";

            // Excel文件名称
            string excelFileName = "Test.xlsx";

            // 表单输入数据
            string formData = txtFormData.Text;

            try
            {
                // 使用ClientContext连接到SharePoint网站
                using (ClientContext context = new ClientContext(siteUrl))
                {
                    // 获取文档库
                    List documentsLibrary = context.Web.Lists.GetByTitle(libraryName);
                    context.Load(documentsLibrary);
                    context.ExecuteQuery();

                    // 上传Excel文件到文档库
                    FileCreationInformation fileCreateInfo = new FileCreationInformation();
                    fileCreateInfo.Url = excelFileName;
                    fileCreateInfo.Content = System.Text.Encoding.UTF8.GetBytes(formData);
                    fileCreateInfo.Overwrite = true;
                    Microsoft.SharePoint.Client.File newFile = documentsLibrary.RootFolder.Files.Add(fileCreateInfo);
                    context.Load(newFile);
                    context.ExecuteQuery();

                    MessageBox.Show("表单数据已成功写入Excel文件。");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("发生错误:" + ex.Message);
            }
        }
    }
}

以上代码使用了Microsoft.SharePoint.Client库来连接到SharePoint网站,并将文本数据作为Excel文件上传到指定的文档库中。你需要将代码中的siteUrllibraryNameexcelFileName替换为你自己的SharePoint网站URL、文档库名称和Excel文件名称。

相关内容

热门资讯

盘点一款“蜀渝牌乐汇辅助”hh... 1、盘点一款“蜀渝牌乐汇辅助”hhpoker免费透视脚本(原来有挂)。2、蜀渝牌乐汇辅助透视辅助简单...
黑科技辅助挂!(wePoke)... 黑科技辅助挂!(wePoke)其实真的是有挂,(wepOKE)一贯有挂,黑科技教程(有挂教程);1、...
重大发现“好友赣南脚本插件”w... 重大发现“好友赣南脚本插件”wepoker私人局有透视吗(原生真的有挂)准备好在好友赣南脚本插件 i...
黑科技辅助挂!(aapokeR... 黑科技辅助挂!(aapokeR)本来有挂,(德州aa扑克)一贯真的是有挂,必赢方法(有挂软件);1....
实测揭晓“家家盘锦开挂”hh ... 实测揭晓“家家盘锦开挂”hh poker软件(本来是真的有挂);小薇(透视辅助)致您一封信;亲爱家家...
黑科技辅助挂!(WPK)其实真... 黑科技辅助挂!(WPK)其实真的有挂,(wpK)切实存在有挂,安装教程(有挂透明挂)1、wpK系统规...
玩家必看分享“开心十三水辅助工... 1、玩家必看分享“开心十三水辅助工具”pokerworld破解版下载(切实是真的有挂);详细教程。2...
黑科技辅助挂!WpK透视辅助,... 黑科技辅助挂!WpK透视辅助,Wpk透视ai辅助,2025教程(有挂神器);1、全新机制【WpK软件...
一秒答解“微乐卡五星有挂吗”w... 一秒答解“微乐卡五星有挂吗”wepoker轻量版透视系统(都是真的是有挂)这是由厦门游乐互动科技有限...
黑科技辅助挂!智星德州菠萝辅助... 黑科技辅助挂!智星德州菠萝辅助器工具,智星德州辅助神器,我来教教你(有挂助手)运智星德州菠萝辅助工具...