下载后我有启动应用程序的代码
client.DownloadFileAsync(new Uri("http://mysite/myapplication.exe"), tempPath + "\\" + sDownloadFileName);
try
{
string tempPath = System.IO.Path.GetTempPath();
Process.Start(tempPath + "myapplication.exe");
Application.Exit();
}
catch
{
MessageBox.Show"Error, the file is corrupt");
}
但是如果文件(http://mysite/myapplication.exe)它不存在.. 一个文件创建相同的1KB,启动和返回错误=( 是否可以阻止执行文件,如果它小到10 MB?
try
{
string tempPath = System.IO.Path.GetTempPath();
if (tempPath + "myapplication.exe" == -10 MB)
{
MessageBox.Show"Error, the file is corrupt");
}
else if
{
Process.Start(tempPath + "myapplication.exe");
}
}
答案 0 :(得分:1)
下载后使用FileInfo
检查尺寸。
try
{
string tempPath = System.IO.Path.GetTempPath();
FileInfo fileInfo = new FileInfo(downloadFilePath);
if (fileInfo.Length < 10*1000*1000)
{
MessageBox.Show"Error, the file is corrupt");
}
else if
{
Process.Start(tempPath + "myapplication.exe");
}
}