Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,
I have a running program that loads the file into SharePoint for me. I have it written with C#. The logic is as follows:

1. I use the command:
net use T: "http://sharepoint_library" /user:MyDomain\MyUser MyPassword]

2. I use another command:
xcopy "file_I_want_to_copy" T:\
3. I disconnect the T: drive with
net use T: /d

So - in other words I map sharepoint library as T: drive and then copy the file to. When done - I disconnect the T: drive so I could reuse it with other files.

The problem here is that I have multiple files to load and I am always using T: drive (other are occupied). So - if I load one file I need to wait until it's loaded so I could start with the other one (this is because each file has different sharepoint libraries so I can not use same T: drive for all files - I need to keep remaping it).

Does anyone know a good way out of this? As far as I know xcopy does not work when you need to copy the files using different credentials, so something like this won't even work:
xcopy "file to copy" "destination" /user:MyDomain\MyUser MyPassword


Thanks in advance!
Posted
Comments
Sunasara Imdadhusen 4-Jun-13 5:59am    
Where is your code?
MK-Gii 4-Jun-13 6:05am    
It's above ;] The lines above should be self explanatory.
If it's not - here is the full code:
protected void File_Copy(string target_file, string destination_directory, string destination_file_name)
{
try
{
File.Copy(Home_Dir + target_file, destination_directory + destination_file_name, true);
}
catch (Exception ex)
{ System.Windows.MessageBox.Show("Error occurred during the copying process \n" + ex.Message); }
}
So - this is a function that I am reusing everywhere. But the idea is the same - it occupies the T: drive during the copy/paste process.
I am mapping the SharePoint list as a shared drive using this approach:
private bool Map_SharePointLib(string SP_Lib_Path,
string UID,
string PassWord)
{
try
{
string cmdStr = "use T: " + SP_Lib_Path + @" /user:MyDomain\" + UID + " " + PassWord;

System.Diagnostics.Process SP_Mapping = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo SP_Mapping_StartInfo = new System.Diagnostics.ProcessStartInfo("net.exe", cmdStr);
SP_Mapping.StartInfo = SP_Mapping_StartInfo;
SP_Mapping.Start();
SP_Mapping.EnableRaisingEvents = true;
SP_Mapping.WaitForExit();
SP_Mapping.Close();
if (Directory.Exists(@"T:\"))
{ return true; }
else
{ return false; }
}
catch (Exception ex)
{ return false; }
}
MK-Gii 6-Jun-13 2:28am    
Hey guys :) Any comment on above?
P.S.: this is just a snippet to show my approach (which is obviously not the best one).
Does anyone have ever used WebServices to upload files to SharePoint? I have found few examples on the net, but thouse are only if you are running the code on the server... in my case - I will be running it on a standalone machine.
Thanks in advance! ;]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900