If the Sharepoint Server requires authentication the
app will fail with a 401 error. It could have a menu
with an option to store the authentication data (but
not to keep it in a file): the user name, password and
domain.
On main.cs add:
using System.Net;
using Microsoft.VisualBasic;
On btnGo_Click at the very begining:
bool AuthFlag = false;
try
{
_Site = txtSite.Text;
initListService();
XmlNode lists = ListService.GetListCollection();
}
catch (Exception ex)
{
if (ex.Message == "The request failed with
HTTP status 401: Unauthorized.")
AuthFlag = true;
}
On btnGo_Click, after initListService(); :
if (AuthFlag)
{
string StrUser =
Interaction.InputBox("User name?", "Authentication", "", -1,
-1);
string StrPWD =
Interaction.InputBox("Password?", "Authentication", "", -1, -1);
string StrDomain =
Interaction.InputBox("Domain?", "Authentication", "", -1, -1);
NetworkCredential n = new
NetworkCredential(StrUser, StrPWD, StrDomain);
_ListService.Credentials = n;
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Logged In: YES
user_id=917965
This worked for me:
add a reference to 'Microsoft.VisualBasic.dll'
On main.cs add:
using System.Net;
using Microsoft.VisualBasic;
On btnGo_Click at the very begining:
bool AuthFlag = false;
try
{
_Site = txtSite.Text;
initListService();
XmlNode lists = ListService.GetListCollection();
}
catch (Exception ex)
{
if (ex.Message == "The request failed with
HTTP status 401: Unauthorized.")
AuthFlag = true;
}
On btnGo_Click, after initListService(); :
if (AuthFlag)
{
string StrUser =
Interaction.InputBox("User name?", "Authentication", "", -1,
-1);
string StrPWD =
Interaction.InputBox("Password?", "Authentication", "", -1, -1);
string StrDomain =
Interaction.InputBox("Domain?", "Authentication", "", -1, -1);
NetworkCredential n = new
NetworkCredential(StrUser, StrPWD, StrDomain);
_ListService.Credentials = n;
}
Logged In: YES
user_id=917965
code to be attached