winform 怎样下载exe 文件,别下载了不能运行啊,我现在就是下载了不能运行啊,运行下载的exe就报错。

winform 怎样下载exe 文件,别下载了不能运行啊,我现在就是下载了不能运行啊,运行下载的exe就报错。,第1张

我的下载代码摘了一段出来,你看看吧:

WebRequest request = WebRequestCreate(downloadUrl);

((HttpWebRequest) request)AllowAutoRedirect = true;

byte[] buffer = new byte[1000000];

using (var response = requestGetResponse())

using (

var stream = new FileStream(savePath, FileModeCreateNew, FileAccessWrite,

FileShareNone))

using (var responseStream = responseGetResponseStream())

{

//var length = (int)responseContentLength;

//fsWrite(brReadBytes(length), 0, length);

long s = streamLength, l = responseContentLength;

int read;

while (!cancelDown && s < l && (read = responseStreamRead(buffer, 0, bufferLength)) != 0)

{

streamWrite(buffer, 0, read);

streamFlush();

s += read;

var percent = (s100/(decimal) l)ToString("N");

}

responseStreamClose();

}

FileStream fstr = new FileStream(“FileUrl”, FileModeOpen, FileAccessRead);

fstrRead();

其中参数"FileUrl"就是你要获取的文件路径,具体你可以去查一下FileStream 或者Stream的用法,希望能帮到你!

FTPConnection ftpConn = new FTPConnection();

DataSet dsXml = new DataSet();

//dsXmlReadXml(xPath);

dsXml = MD5EncryptDESinstance()DecryptXML2DS(xPath, 1);

//读取ftp配置信息

ftpConnUserName = dsXmlTables["FtpSet"]Rows[0]["UserName"]ToString();

ftpConnPassword = dsXmlTables["FtpSet"]Rows[0]["Password"]ToString();

ftpConnServerAddress = dsXmlTables["FtpSet"]Rows[0]["ServerAddress"]ToString();

ftpConnServerPort = ConvertToInt32(dsXmlTables["FtpSet"]Rows[0]["ServerPort"]ToString());

ftpConnTransferType = FTPTransferTypeBINARY;

try

{

ftpConnConnect();

ftpConnChangeWorkingDirectory(ftpPath);

FTPFile[] filelist = ftpConnGetFileInfos(ftpPath);

foreach (FTPFile ftpfile in filelist)

{

if (ftpfileDir)

continue;

if (!DirectoryExists(sSaveFilePath))

DirectoryCreateDirectory(sSaveFilePath);

ftpConnDownloadFile(localfilename, ftpfileName);

}

}

catch (Exception ex)

{

SendLog(exToString());

}

finally

{

try

{

if (ftpConnIsConnected)

ftpConnClose();

}

catch (Exception ex)

{

SendLog("关闭FTP连接异常:" + exToString());

}

}

其中用到一个dll 在网上有的 可以自己去下载edtFTPnetdll,稍微修改下,就可以用了

下载完以后,要释放占用的资源。

FileStream mhj = new FileStream();

mhjDispose();//结束释放占用资源

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » winform 怎样下载exe 文件,别下载了不能运行啊,我现在就是下载了不能运行啊,运行下载的exe就报错。

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情