如何清除此错误:无法将类型'System.Net.WebRequest'隐式转换为'System.Net.FtpWebRequest'。存在显式转换(您是否错过了演员?) [英] How to remove this error: Cannot implicitly convert type 'System.Net.WebRequest' to 'System.Net.FtpWebRequest'. An explicit conversion exists (are you missing a cast?)
本文介绍了如何清除此错误:无法将类型'System.Net.WebRequest'隐式转换为'System.Net.FtpWebRequest'。存在显式转换(您是否错过了演员?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到此错误如何删除它:
无法将类型'System.Net.WebRequest'隐式转换为'System.Net.FtpWebRequest' 。存在显式转换(你错过了演员吗?)
我的代码在这里:
public bool Upload(byte [] FileByte,string FileName ,字符串ftpUserID,字符串ftpPassword,字符串ftpURL)
{
bool retValue = false;
尝试
{
string ftpFullPath =// elink / Keshav / Images / Emp Docs;
FtpWebRequest ftp = FtpWebRequest.Create(new Uri(ftpFullPath));
ftp.Credentials = new NetworkCredential(keshav,abc @ 789);
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
Stream ftpStream = ftp.GetRequestStream();
ftpStream.Write(FileByte,0,FileByte.Length);
ftpStream.Close();
ftpStream.Dispose();
retValue = true;
}
catch(exception ex)
{
throw ex;
}
返回retValue;
}
解决方案
更改
FtpWebRequest ftp = FtpWebRequest.Create (new Uri(ftpFullPath));
to
FtpWebRequest ftp =(FtpWebRequest)WebRequest.Create(new Uri (ftpFullPath));
Hi,
I am facing this error how to remove it:
Cannot implicitly convert type 'System.Net.WebRequest' to 'System.Net.FtpWebRequest'. An explicit conversion exists (are you missing a cast?)
My Code is here:
public bool Upload(byte[] FileByte, string FileName, string ftpUserID, string ftpPassword, string ftpURL) { bool retValue = false; try { string ftpFullPath = "//elink/Keshav/Images/Emp Docs"; FtpWebRequest ftp = FtpWebRequest.Create(new Uri(ftpFullPath)); ftp.Credentials = new NetworkCredential("keshav", "abc@789"); ftp.KeepAlive = true; ftp.UseBinary = true; ftp.Method = WebRequestMethods.Ftp.UploadFile; Stream ftpStream = ftp.GetRequestStream(); ftpStream.Write(FileByte, 0, FileByte.Length); ftpStream.Close(); ftpStream.Dispose(); retValue = true; } catch (Exception ex) { throw ex; } return retValue; }
解决方案
Change
FtpWebRequest ftp = FtpWebRequest.Create(new Uri(ftpFullPath));
to
FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create(new Uri(ftpFullPath));
这篇关于如何清除此错误:无法将类型'System.Net.WebRequest'隐式转换为'System.Net.FtpWebRequest'。存在显式转换(您是否错过了演员?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文