![](/img/trans.png)
[英]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.