Member 13818142 Ответов: 2

Не все пути кода возвращают значение C#


Привет, у меня есть возврат ниже кода для загрузки файлов и перемещения файла в папку, в которой я написал отдельные функции и должен их вызывать. но я получаю ошибку, так как "не все пути кода возвращают значение", пожалуйста, предложите, где я ошибся.

Что я уже пробовал:

 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);			                   
		 }
  }
}

2 Ответов

Рейтинг:
1

Mark Storen

Метод upload имеет возвращаемый тип int, но он не возвращает никакого значения.


Рейтинг:
0

Mark Storen

Попробуйте что-нибудь вроде этого:

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;
           }


таким образом, обе точки выхода имеют возврат.