Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, i have return below code for upload files and move file to a folder i have written separate functions and need to call them. but i am getting the error as "NOT ALL CODE PATHS RETURNS A VALUE" please suggest where i went wrong.

What I have tried:

 public void BtnUploadClick(object sender, EventArgs e)
		{
		 	try{
            int CheckBoxRowCounter = 0;            
            for (int i = 0; i < dataGridView1.RowCount; i++)
            {
                if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value))
                {
                    CheckBoxRowCounter++;
                }
            }
             if (CheckBoxRowCounter > 0) 
             {
                  //  String folderPath = folderBrowserDlg.SelectedPath;
                    for (int i = 0; i < dataGridView1.RowCount; i++)
                    {
                        if (Convert.ToBoolean(dataGridView1.Rows[i].Cells[0].Value))
                        {
                            string SourceFilePath = dataGridView1.Rows[i].Cells[1].Value.ToString();
                            string FileName = new System.IO.FileInfo(SourceFilePath).Name;
                             Encrypt_and_decrypt.AES a  = new AES();                            
                            string TargetFilePath = _SelectedPath + @"\" + FileName;    
                             FileInfo file1=new FileInfo(SourceFilePath);		
                             a.EncryptFile(SourceFilePath,"D:\\test"+file1.Extension.ToString(),Hidkey[0,1].ToString());                             
                           //upload                       
                                        				                       
                            //Move upload                                    
				                 
                       }
                    }
                    MessageBox.Show("Selected Files Moved.Refreshing Grid...");
                    FillGridView();
             }
					 else
            {
                MessageBox.Show("Please select item(s).");
            }
					 //return upload(SourceFile;destinationfile);
			}
			catch( Exception e3)
			{
				MessageBox.Show(e3.Message);
			}
      	}  

		 public int upload(string SourceFile,string destinationfile)
		 {
		 	try{
		 	       		using (WebClient client = new WebClient())
		             	  {
			          		  client.Credentials = new NetworkCredential("username", "password");     
							  client.UploadFile("ftpaddress" + SourceFile, destinationfile);			          		  
		                	}
                           File.Delete(destinationfile);   
		 	}
		 
		 	catch(Exception e)
		 	{
		 		MessageBox.Show(e.Message);
		 	}
		 }
		 public void move(string sourcefile,string destfile)
		 {
		 	string subFolder = Path.Combine(_SelectedPath, "UPLOAD");
		        if (!Directory.Exists(subFolder))				
			      {				
		              Directory.CreateDirectory(subFolder);				
	              }
	               String Todaysdate = DateTime.Now.ToString("MMM-dd-yyyy");
	               string datefolder = Path.Combine(subFolder,Todaysdate);
			      if(!Directory.Exists(datefolder))
		          {
			    	Directory.CreateDirectory(datefolder);
			      }
		            string sourcePath = _SelectedPath;
			        string targetPath = datefolder;
				    string sourceFile = System.IO.Path.Combine(sourcePath, FileName);
			        string destFile = System.IO.Path.Combine(targetPath, FileName);						                 
				    //destFile = System.IO.Path.Combine(targetPath, FileName);
				     System.IO.File.Move(sourceFile, destFile);			                   
		 }
  }
}
Posted
Updated 16-May-18 18:53pm

The upload method has a return type of int but it's not returning any value.
 
Share this answer
 
Try something like this:

C#
public int upload(string SourceFile,string destinationfile)
        {
           try{
                       using (WebClient client = new WebClient())
                         {
                             client.Credentials = new NetworkCredential("username", "password");
                             client.UploadFile("ftpaddress" + SourceFile, destinationfile);
                           }
                          File.Delete(destinationfile);
                          return 1;
           }

           catch(Exception e)
           {
               MessageBox.Show(e.Message);
                               return 0;
           }


so both exit points have a return.
 
Share this answer
 

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