[英]Windows Application Sharepoint CSOM
我正在創建一個 Windows 窗體應用程序,我應該在其中使用文本框從用戶那里獲取共享點 url,並從用戶那里獲取用戶名和密碼,並檢查與站點的連接是否成功並顯示相應的成功消息。
我已經創建了基本表單並添加了對應用程序的引用。 我無法通過從文本字段中獲取站點 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)
{
}
}
}
我想通過檢查與站點的連接你可能意味着檢查與數據庫的連接,在這種情況下我會推薦做這樣的事情:
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 服務器的連接,您可以向服務器發送請求並檢查是否收到響應
希望這有幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.