0

I am creating a windows form application in which I am supposed to take the share point url from the user by using a textbox and get the username and password also from the user and check the connection to the site if it is successful or not and display a success message accordingly.

I have created the basic form and added the references to the application. I am unable to add the logic for the check connection by taking the site url, username and password from the text fields.

This is the codebase that I am using:

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)
        {

        }
    }
}
James Z
  • 12,209
  • 10
  • 24
  • 44
Tarun
  • 1

1 Answers1

0

I imagine by check connection to site you might mean check connection to the database in which case I would recomend doing something like this:

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"

more info here

However if you mean check connection to a web server you could send a request to the server and check if you get a response back

hopefully this helps

Aleks4920
  • 82
  • 7
  • Hey thanks for the response. but by check connection I meant if the application i have on my local host is successfully connecting to the sharepoint site. – Tarun Dec 20 '22 at 15:33