并非所有代码路径都返回值C#

编程入门 行业动态 更新时间:2024-10-27 06:21:23
本文介绍了并非所有代码路径都返回值C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经返回下面的上传文件代码并将文件移动到我编写了单独的函数的文件夹,需要调用它们。但我收到的错误是并非所有代码路径都返回值请告诉我哪里出错了。 我尝试了什么:

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

推荐答案

上传方法的返回类型为int但它是没有返回任何值。 The upload method has a return type of int but it's not returning any value.

尝试这样的事情: Try something like this: 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.

更多推荐

并非所有代码路径都返回值C#

本文发布于:2023-11-10 01:20:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573970.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   返回值   代码

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!