I'm working with a program that uploads to site folders, using C# and WSS3, and I am trying to ensure that it works correctly with Sharepoint permissions.
In my test program for the Frontpage RPC method which I am using to upload, which uses exactly the same classes for the actual functionality as my "live" program, when files are uploaded they appear with my full name next to them.
If I upload a file through my live application the uploaded file modified by name appears as MYDOMAIN\MYCOMPUTERNAME$ this isn't what I expected as I am logged on to an Active Directory account not the local computer account.
I have tried this using CredentialsCache.DefaultNetworkCredentials or .NetworkCredentials and new NetworkCredential(myUsername, myPass, myDomain) as credentials for the WebClient credentials, but all have the same result.
The only difference is the way in which they are being called upon, the test is a simple Forms project. The live version uses reflection to load up a script, which contains the same code as my test project. Aside from that they use the same method with the same Data so the results should be the same, although they aren't.
object o = results.CompiledAssembly.CreateInstance("Script");
Type type = o.GetType();
MethodInfo m = type.GetMethod("Main");
try
{
Object returnVal = m.Invoke(o, new object[] { item.ScanDoc });
if (returnVal == null)
{
executionSuccessful = true;
}
}
This doesn't fit my needs, as different users intended to have different permissions are likely to use the same computer. We also want to know who uploaded which documents.
I have an idea on how I can restrict users access to places they should't be able to upload to by calculating their permissions from the masks associated with their account that I can return via the web services.
I have no idea how I can change the "modified by" name or why reflection is causing a difference in result. Does anyone have any ideas what is causing it show my local computer name and how I can bypass this issue?
Edit
public static String DoUpload(string destinationUrl, byte[] bytes, Dictionary<string, object> metaInfo)
{
string result = "";
// Substring URL until and attempt communication until root site found.
string webUrl = GetWebURL(destinationUrl);
if (webUrl == "Access Denied")
{
throw new Exception("Access Denied - Verify your account has full control on target website.");
}
string documentName = destinationUrl.Substring(webUrl.Length + 1);
return DoUpload(webUrl, documentName, bytes, metaInfo, out result);
}
public static String DoUpload(string webUrl, string documentName, byte[] bytes, Dictionary<string, object> metaInfo, out string result)
{
string putOption = "overwrite,createdir,migrationsemantics"; // See http://msdn2.microsoft.com/en-us/library/ms455325.aspx
string comment = null;
bool keepCheckedOut = false;
// execute put doc method
string method = "method=put+document%3a12.0.4518.1016&service_name=%2f&document=[document_name={0};meta_info=[{1}]]&put_option={2}&comment={3}&keep_checked_out={4}\n";
method = String.Format(method, documentName, EncodeMetaInfo(metaInfo), putOption, HttpUtility.UrlEncode(comment), keepCheckedOut.ToString().ToLower());
List<byte> data = new List<byte>();
data.AddRange(Encoding.UTF8.GetBytes(method));
data.AddRange(bytes);
try
{
using (WebClient webClient = new WebClient())
{
webClient.Credentials = CredentialCache.DefaultNetworkCredentials;
webClient.Headers.Add("Content-Type", "application/x-vermeer-urlencoded");
webClient.Headers.Add("X-Vermeer-Content-Type", "application/x-vermeer-urlencoded");
result = Encoding.UTF8.GetString(webClient.UploadData(webUrl + "/_vti_bin/_vti_aut/author.dll", "POST", data.ToArray()));
}
}
catch (Exception ex)
{
result = ex.Message;
}
return result;
}
Edit2
Looking into cause of highlighted differences now.

