Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i am working in uploading files with WCF web service,
here's my code for uploading



C#
public string UploadTransactionsFile(string uploadPath)
           {
               string uploadTransactionsFile;

               if (String.IsNullOrEmpty(uploadPath))
                   return string.Empty;

               if (!ValidateTransactionsFile(uploadPath))
                   return string.Empty;

               try
               {
                   var dir = @"C:\Upload\";
                   string myUploadPath = dir;
                   var myFileName = Path.GetFileName(uploadPath);
                   CheckDirectory(myUploadPath);

                   var client = new WebClient { Credentials = CredentialCache.DefaultCredentials };

                  client.UploadFile(myUploadPath + myFileName, "PUT", uploadPath);
                   client.Dispose();


                   uploadTransactionsFile = "ok";
               }
               catch (Exception ex)
               {
                   uploadTransactionsFile = ex.Message;
               }

               return uploadTransactionsFile;
           }


i create a windows form as a test client and add the service reference,

my code in calling the method and hardcoded the file i want to upload:

C#
private testServiceClient testService;
     private void Button_Click(object sender, RoutedEventArgs e)
            {
                var File = "C:\\file.csv";
                testService = new testServiceClient();
    
                testService.UploadTransactionFile(File);
    
            }


i can upload files using one computer, but when i put my test client to another computer,
i can't, because the file is just passing the stringpath, which will cannot find in server computer.

am i missing something? help me pls, do i have to send my file as byte[]? how to do this?
Posted
Updated 17-Sep-13 17:29pm
v2

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