.net Windows应用程序Sharepoint CSOM

bbuxkriu  于 2022-12-24  发布在  .NET
关注(0)|答案(1)|浏览(104)

我正在创建一个windows表单应用程序,其中我应该采取共享点的网址从用户使用文本框,并获得用户名和密码也从用户和检查连接到网站,如果它是成功的或没有,并显示相应的成功消息。
我已经创建了基本的表单,并添加了对应用程序的引用。我无法通过从文本字段中获取站点URL、用户名和密码来添加检查连接的逻辑。
这是我正在使用的代码库:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SPClient=Microsoft.SharePoint.Client;

namespace WindowsFormsApp1
{
    public partial class MigraterApp : Form
    {
        public MigraterApp()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void label1_Click_1(object sender, EventArgs e)
        {

        }

        private void label1_Click_2(object sender, EventArgs e)
        {

        }

        private void textBox3_TextChanged(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtSharepoint.Checked)
            {
                txtUserName.Enabled = true;
                txtPassword.Enabled = true;
                lblUsername.Enabled = true;
                lblPass.Enabled = true;
                txtSharePointURL.Enabled = true;
                lblSharepointURL.Enabled = true;
                txtSourceMailBox.Enabled = true;
                lblSourcemail.Enabled = true;
                txtTempDownPath.Enabled = true;
                lbltempPath.Enabled = true;

                txtFileSharepath.Enabled = false;
                lblSharePath.Enabled = false;
                txtDestinationMailBox.Enabled = false;                        
                lblDestinationmailBox.Enabled = false;
            }
        }

        private void ExampleUsername_Click(object sender, EventArgs e)
        {

        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }

        private void FileShare_CheckedChanged(object sender, EventArgs e)
        {
            if (FileShare.Checked)
            {
                txtSourceMailBox.Enabled = true;
                lblSourcemail.Enabled = true;                 
                txtFileSharepath.Enabled = true;
                lblSharePath.Enabled = true;
                txtTempDownPath.Enabled = true;
                lbltempPath.Enabled = true;

                txtUserName.Enabled = false;
                txtPassword.Enabled = false;                
                txtSharePointURL.Enabled = false;
                txtDestinationMailBox.Enabled = false;
                lblUsername.Enabled = false;
                lblPass.Enabled = false;
                lblSharepointURL.Enabled = false;                
                lblDestinationmailBox.Enabled = false;

            }
        }

        private void GMBMail_CheckedChanged(object sender, EventArgs e)
        {
            if (GMBMail.Checked)
            {
                txtDestinationMailBox.Enabled = true;
                txtTempDownPath.Enabled = true;
                lblDestinationmailBox.Enabled = true;
                lbltempPath.Enabled = true;
                txtSourceMailBox.Enabled = true;
                lblSourcemail.Enabled = true;
                
                txtFileSharepath.Enabled = false;
                lblSharePath.Enabled = false;
                txtUserName.Enabled = false;
                txtPassword.Enabled = false;
                lblUsername.Enabled = false;
                lblPass.Enabled = false;
                txtSharePointURL.Enabled = false;
                lblSharepointURL.Enabled = false;
            }
        }
        private void txtSharePointURL_Click(object sender, EventArgs e)
        {

        }

        private void CheckConnection_Click(object sender, EventArgs e)
        {

        }
    }
}
pcww981p

pcww981p1#

我想通过检查连接到网站,你可能意味着检查连接到数据库,在这种情况下,我会建议这样做:

Function Check-SQLServerConnection([string]$serverInstance)
{
$connectionString = "Data Source={0};Integrated Security=true;Application 
Name=CheckSQLServer" -f $serverInstance;
$sqlConn = new-object("Data.SqlClient.SQLConnection") $connectionString;

Write-Host $connectionString

try {
    $sqlConn.Open();
    $sqlConn.Close();
    Write-Host "Connected OK"-foregroundcolor white -backgroundcolor green
}
catch {
    Write-Host $_ -foregroundcolor white -backgroundcolor red
}
finally {
    $sqlConn.Dispose();
}
}
#Call the function with your SQL Server Machine Name
Check-SQLServerConnection "SP13-SQL01"

更多信息在这里
但是,如果您的意思是检查与Web服务器的连接,则可以向服务器发送请求,然后检查是否收到响应
希望这能有所帮助

相关问题