954,525 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Upload file on local server

My project is simple desktop application.
I want to transfer(upload) a file from my desktop to
the another machine which is server of my machine.(One machine to another )
There is nothing to do with web service.
Can anybody send me help ?

Thanks in advance.

Nitin Daphale
Junior Poster in Training
64 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace ConsoleApplication1
{
class Program
{

public static void Main()
{
string sourcepath = @"c:\MyTest.txt";
string path2 = @"\\10.2.55.184\Share\Team\Jitinder\MyTest.txt";

try
{
// Create the file and clean up handles.

// Ensure that the target does not exist.
//File.Delete(path2);

// Copy the file.
File.Copy(sourcepath, path2,true);
Console.WriteLine("{0} copied to {1}", sourcepath, path2);

// // Try to copy the same file again, which should succeed.
// File.Copy(sourcepath, path2, true);
// Console.WriteLine("The second Copy operation succeeded, which was expected.");
//
}

catch
{
Console.WriteLine("Double copy is not allowed, which was not expected.");
}


}
}
}

make sure u can access \\10.2.55.184\Share\Team\Jitinder\

u can directly do from explorer also

jinus
Newbie Poster
20 posts since Feb 2008
Reputation Points: 10
Solved Threads: 1
 

using System; using System.Collections.Generic; using System.Text; using System.IO;

namespace ConsoleApplication1 { class Program {

public static void Main() { string sourcepath = @"c:\MyTest.txt"; string path2 = @"\\10.2.55.184\Share\Team\Jitinder\MyTest.txt";

try { // Create the file and clean up handles.

// Ensure that the target does not exist. //File.Delete(path2);

// Copy the file. File.Copy(sourcepath, path2,true); Console.WriteLine("{0} copied to {1}", sourcepath, path2);

// // Try to copy the same file again, which should succeed. // File.Copy(sourcepath, path2, true); // Console.WriteLine("The second Copy operation succeeded, which was expected."); // }

catch { Console.WriteLine("Double copy is not allowed, which was not expected."); }

} } }

make sure u can access \\10.2.55.184\Share\Team\Jitinder\

u can directly do from explorer also

Thanks jinus
it's working with slight changes

Nitin Daphale
Junior Poster in Training
64 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You