不同机器上的多个用户是否可以通过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文件名称。

相关内容

热门资讯

黑科技科技(wepoke智能a... 黑科技科技(wepoke智能ai)wepower使用说明书(wepOkE)素来是真的有挂(确实有挂)...
黑科技模拟器(wepoke智能... WePoker透视辅助工具核心要点解析‌,黑科技模拟器(wepoke智能ai)wepoke是机器发牌...
黑科技脚本(wepokeai代... 您好,这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩家在这款游戏中打牌都...
黑科技辅助挂(wepoke真的... 黑科技辅助挂(wepoke真的有挂)wepoke 软件(wEPOKE)固有真的有挂(有挂猫腻)-哔哩...
黑科技辅助挂(wepoke黑科... 黑科技辅助挂(wepoke黑科技)wepoke软件透明挂演示(wEpOke)一直真的有挂(真的有挂)...
黑科技app(wepoke真的... 此外,数据分析德州()辅助神器app还具备辅助透视行为开挂功能,通过对客户透明挂的深入研究,你可以了...
黑科技智能ai(wepoke辅... 黑科技智能ai(wepoke辅助插件)wepoke软件透明(WEPOke)先前是有挂(果真有挂)-哔...
黑科技模拟器(wepoke透明... 黑科技模拟器(wepoke透明黑科技)wepoke德州扑克用ai代打(WEPOKE)最初存在有挂(有...
黑科技插件(wepoke辅助插... 黑科技插件(wepoke辅助插件)wepoke软件透明(WEPOke)从来是真的有挂(有挂解惑)-哔...
黑科技美元局(wepoke智能... 黑科技美元局(wepoke智能ai)wepoke辅助真的假的(wepoKE)原先真的有挂(竟然有挂)...