1.首先,需要指定获取的文件夹,以及获取文件的文件名;
文件夹:strlocalpath = system.windows.forms.application.startuppath + "\\exceltemplate\\";
文件名:temp.xlsx
2.代码:
executionresult result = new executionresult(); result.status = true; string strlocalpath = system.windows.forms.application.startuppath + "\\exceltemplate\\"; if (directory.exists(strlocalpath)) { foreach (string gcfile in directory.getfiles(strlocalpath, "temp.xlsx", searchoption.topdirectoryonly)) { string filename = path.getfilename(gcfile); string filename = path.getfilename(gcfile).replace(".xlsx", "") + datetime.now.tostring("_yyyymmdd") + ".xlsx"; try { file.copy(strlocalpath + filename, strlocalpath + "temp\\" + filename, true); result = geta31daydata(strlocalpath + "temp\\" + filename); } catch (exception ex) { result.status = false; result.message = "copy file to destination file exception. msg:" + ex.message; result.anything = ex.message; if (meslog.iserrorenabled) { meslog.error(ex.stacktrace); } } } } else { result.status = false; result.message = "directory not exists!"; } return result;
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论