K
Ken McAndrew
I'm working with a client that has Windows Server 2003, WSS, accessed
through a custom application. In this application, we need to attach files
to cases by adding them to a database and storing them in Sharepoint. This
process works fine at our office, but the client is having authentication
problems.
The only authentication being used is Windows security. Before, my
Sharepoint code (in C#) was in a file, and the users would get a login
prompt. However, even if they entered correct information, it would not let
them in and eventually give an Unauthorized (401.1) error. I decided to move
the functionality to a web service and use the Credentials object to set up
authentication. These are the calls in my web page:
pmdtc_ws.CreateSite svcCreateSite = new PMDTC.pmdtc_ws.CreateSite();
svcCreateSite.Credentials =
System.Net.CredentialCache.DefaultCredentials;
string strResult = svcCreateSite.AttachFile(subWeb, sFileName,
pFileContents);
And this is the web service's method:
[WebMethod]
public string AttachFile(string pFolderID, string pFileName, byte[]
pFileContents)
{
string strMessage;
try
{
SPSite site = SPControl.GetContextSite(Context);
SPWeb web;// = SPControl.GetContextWeb(Context);
string tmpSite = site.Url;
if (pFolderID != "0")
{
tmpSite += "/" + pFolderID + "/";
}
tmpSite = tmpSite.Substring(7);
int posSite = tmpSite.IndexOf("/");
tmpSite = tmpSite.Substring(posSite);
web = site.OpenWeb(tmpSite);
web.AllowUnsafeUpdates = true;
SPFolder folder;
SPFile file;
folder = web.GetFolder("Shared Documents");
file = web.GetFile(folder.Url + "/" + pFileName);
if (file.Exists) ////check in existing file
{
file.CheckOut();
file.SaveBinary(pFileContents);
file.CheckIn(""); ////We have to force the checkin here.
}
else ////Add a new file
{
SPFileCollection files;
files = folder.Files;
files.Add(folder.Url + "/" + pFileName, pFileContents);
}
strMessage = "Success!";
}
catch (Exception ex)
{
strMessage = "Fail! " + ex.Message.ToString();
}
return strMessage;
}
When I run this, I get back an ASP.Net error page, that says the user is
unauthorized: 401, treating it as an unhandled exception. (As a note, users
have Contributer permissions in Sharepoint, and a cross-site group with
Contributer permissions is set up for the subsites that files might be
stored to, but this happens at any level.)
We found that if the administrator does a file attach, it will work, and
allow access to the site for a time, before it loses that access. Also, when
I used a standard user (having the problem) to access the Sharepoint site,
we got this error message:
"Error
List does not exist
The page you selected contains a list that does not exist. It may have been
deleted by another user. Click "Home" at the top of the page to return to
your Web site."
There was a fix mentioned on Google for this, giving users read access to
the webtemp.xml file in Templates/1033/XML, but that worked only until we
rebooted the machine.
I've been trying to figure this out for a few weeks now with no success, so
any help would be extremely appreciated. Thanks.
through a custom application. In this application, we need to attach files
to cases by adding them to a database and storing them in Sharepoint. This
process works fine at our office, but the client is having authentication
problems.
The only authentication being used is Windows security. Before, my
Sharepoint code (in C#) was in a file, and the users would get a login
prompt. However, even if they entered correct information, it would not let
them in and eventually give an Unauthorized (401.1) error. I decided to move
the functionality to a web service and use the Credentials object to set up
authentication. These are the calls in my web page:
pmdtc_ws.CreateSite svcCreateSite = new PMDTC.pmdtc_ws.CreateSite();
svcCreateSite.Credentials =
System.Net.CredentialCache.DefaultCredentials;
string strResult = svcCreateSite.AttachFile(subWeb, sFileName,
pFileContents);
And this is the web service's method:
[WebMethod]
public string AttachFile(string pFolderID, string pFileName, byte[]
pFileContents)
{
string strMessage;
try
{
SPSite site = SPControl.GetContextSite(Context);
SPWeb web;// = SPControl.GetContextWeb(Context);
string tmpSite = site.Url;
if (pFolderID != "0")
{
tmpSite += "/" + pFolderID + "/";
}
tmpSite = tmpSite.Substring(7);
int posSite = tmpSite.IndexOf("/");
tmpSite = tmpSite.Substring(posSite);
web = site.OpenWeb(tmpSite);
web.AllowUnsafeUpdates = true;
SPFolder folder;
SPFile file;
folder = web.GetFolder("Shared Documents");
file = web.GetFile(folder.Url + "/" + pFileName);
if (file.Exists) ////check in existing file
{
file.CheckOut();
file.SaveBinary(pFileContents);
file.CheckIn(""); ////We have to force the checkin here.
}
else ////Add a new file
{
SPFileCollection files;
files = folder.Files;
files.Add(folder.Url + "/" + pFileName, pFileContents);
}
strMessage = "Success!";
}
catch (Exception ex)
{
strMessage = "Fail! " + ex.Message.ToString();
}
return strMessage;
}
When I run this, I get back an ASP.Net error page, that says the user is
unauthorized: 401, treating it as an unhandled exception. (As a note, users
have Contributer permissions in Sharepoint, and a cross-site group with
Contributer permissions is set up for the subsites that files might be
stored to, but this happens at any level.)
We found that if the administrator does a file attach, it will work, and
allow access to the site for a time, before it loses that access. Also, when
I used a standard user (having the problem) to access the Sharepoint site,
we got this error message:
"Error
List does not exist
The page you selected contains a list that does not exist. It may have been
deleted by another user. Click "Home" at the top of the page to return to
your Web site."
There was a fix mentioned on Google for this, giving users read access to
the webtemp.xml file in Templates/1033/XML, but that worked only until we
rebooted the machine.
I've been trying to figure this out for a few weeks now with no success, so
any help would be extremely appreciated. Thanks.