[英]Copy a file from one server folder to another folder using webservice
[英]Get xslx and xls file from a folder and copy it in another folder
我想使用 c# 从文件夹中下载 xlsx 和 xls 文件。我尝试过以下方式:
foreach (DriveInfo mydrive in mydrives)
{
if (mydrive.DriveType != DriveType.Removable)
{
if (mydrive.DriveType == DriveType.CDRom)
{
}
if (mydrive.DriveType != DriveType.CDRom)
{
var sourceDirectory = mydrive.Name;
string[] files = System.IO.Directory.GetFiles(sourceDirectory, "*xlsx");
foreach (var txtfiles in files)
{
string sourceFile = txtfiles;
string filename = null;
filename = Path.GetFileName(sourceFile);
string destinationFile = @"E:\Prog\" + filename;
File.Copy(sourceFile, destinationFile, true);
}
}
}
}
我的代码只获取 xlsx 文件我需要 xlsx 和 xls 文件。
尝试改变
string[] files = System.IO.Directory.GetFiles(sourceDirectory, "*xlsx");
到
string[] files = System.IO.Directory.GetFiles(sourceDirectory, "*.xls");
这将匹配sourceDirectory
以.xls
或.xlsx
结尾的任何文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.