10 个解决方案
#1
求大侠
#4
可以用文件流。。就三四句话。。不过现在不在公司。。。给不了代码,如果需要可以礼拜一给你
#5
通过使用FTPwebrequest上传文件
或web services
private bool FtpUpFile(string strFileName,string strFtpUrl,string strFtpUser,string strFtpPassword)
{
try
{
FileInfo fileInf = new FileInfo(strFileName);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFtpUrl + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(strFtpUser, strFtpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.OpenRead();
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
int allbye = (int)fileInf.Length;
int startbye = 0;
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
startbye += contentLen;
}
strm.Close();
fs.Close();
return true;
}
catch
{
return false;
}
}
或web services
private bool FtpUpFile(string strFileName,string strFtpUrl,string strFtpUser,string strFtpPassword)
{
try
{
FileInfo fileInf = new FileInfo(strFileName);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFtpUrl + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(strFtpUser, strFtpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.OpenRead();
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
int allbye = (int)fileInf.Length;
int startbye = 0;
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
startbye += contentLen;
}
strm.Close();
fs.Close();
return true;
}
catch
{
return false;
}
}
#6
cs端的这个还是好做一点的。
http://blog.csdn.net/linxuliang/article/details/6856087
ftp上传方式。
http://www.blogjava.net/kiant/articles/277929.html
websocket方式。
http://blog.csdn.net/linxuliang/article/details/6856087
ftp上传方式。
http://www.blogjava.net/kiant/articles/277929.html
websocket方式。
#7
楼上几位大侠的法子已经搞定能实现了,但还是想看看你的怎么用文件流 三四句话实现,先结贴希望你周一再贴出来看看
#8
找到了,以前回答过
string filePath = Request["UpFile"];
//开始上传
//获取要保存的文件信息
FileInfo file = new FileInfo(filePath);
//获取文件扩展名
string fileExtenName = file.Extension;
//重命名文件
string fileNewName = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtenName;
//保存路径
string fileSavePath = Server.MapPath(@"~\uploadFile\images\lineimages\") + fileNewName;
///真正上传就是从这里开始,这是ASP.NET,记得winform也是一样的
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
//把文件流中转化成字节数组
byte[] imageBytes = new byte[(int)fs.Length];
fs.Read(imageBytes, 0, imageBytes.Length);
fs.Close();
MemoryStream ms = new MemoryStream(imageBytes);//定义并实例化一个内存流,以存放提交上来的字节数组。
FileStream fss = new FileStream(fileSavePath, FileMode.Create);
ms.WriteTo(fss);
fss.Close();
ms.Close();
XML没试过,可以试下
string filePath = Request["UpFile"];
//开始上传
//获取要保存的文件信息
FileInfo file = new FileInfo(filePath);
//获取文件扩展名
string fileExtenName = file.Extension;
//重命名文件
string fileNewName = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtenName;
//保存路径
string fileSavePath = Server.MapPath(@"~\uploadFile\images\lineimages\") + fileNewName;
///真正上传就是从这里开始,这是ASP.NET,记得winform也是一样的
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
//把文件流中转化成字节数组
byte[] imageBytes = new byte[(int)fs.Length];
fs.Read(imageBytes, 0, imageBytes.Length);
fs.Close();
MemoryStream ms = new MemoryStream(imageBytes);//定义并实例化一个内存流,以存放提交上来的字节数组。
FileStream fss = new FileStream(fileSavePath, FileMode.Create);
ms.WriteTo(fss);
fss.Close();
ms.Close();
XML没试过,可以试下
#9
这个方法不行吧。filestream只认服务器路径
#10
楼主你是用的哪个方法搞定实现的啊..??
#1
求大侠
#2
#3
#4
可以用文件流。。就三四句话。。不过现在不在公司。。。给不了代码,如果需要可以礼拜一给你
#5
通过使用FTPwebrequest上传文件
或web services
private bool FtpUpFile(string strFileName,string strFtpUrl,string strFtpUser,string strFtpPassword)
{
try
{
FileInfo fileInf = new FileInfo(strFileName);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFtpUrl + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(strFtpUser, strFtpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.OpenRead();
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
int allbye = (int)fileInf.Length;
int startbye = 0;
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
startbye += contentLen;
}
strm.Close();
fs.Close();
return true;
}
catch
{
return false;
}
}
或web services
private bool FtpUpFile(string strFileName,string strFtpUrl,string strFtpUser,string strFtpPassword)
{
try
{
FileInfo fileInf = new FileInfo(strFileName);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(strFtpUrl + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(strFtpUser, strFtpPassword);
reqFTP.KeepAlive = false;
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
FileStream fs = fileInf.OpenRead();
Stream strm = reqFTP.GetRequestStream();
contentLen = fs.Read(buff, 0, buffLength);
int allbye = (int)fileInf.Length;
int startbye = 0;
while (contentLen != 0)
{
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
startbye += contentLen;
}
strm.Close();
fs.Close();
return true;
}
catch
{
return false;
}
}
#6
cs端的这个还是好做一点的。
http://blog.csdn.net/linxuliang/article/details/6856087
ftp上传方式。
http://www.blogjava.net/kiant/articles/277929.html
websocket方式。
http://blog.csdn.net/linxuliang/article/details/6856087
ftp上传方式。
http://www.blogjava.net/kiant/articles/277929.html
websocket方式。
#7
楼上几位大侠的法子已经搞定能实现了,但还是想看看你的怎么用文件流 三四句话实现,先结贴希望你周一再贴出来看看
#8
找到了,以前回答过
string filePath = Request["UpFile"];
//开始上传
//获取要保存的文件信息
FileInfo file = new FileInfo(filePath);
//获取文件扩展名
string fileExtenName = file.Extension;
//重命名文件
string fileNewName = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtenName;
//保存路径
string fileSavePath = Server.MapPath(@"~\uploadFile\images\lineimages\") + fileNewName;
///真正上传就是从这里开始,这是ASP.NET,记得winform也是一样的
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
//把文件流中转化成字节数组
byte[] imageBytes = new byte[(int)fs.Length];
fs.Read(imageBytes, 0, imageBytes.Length);
fs.Close();
MemoryStream ms = new MemoryStream(imageBytes);//定义并实例化一个内存流,以存放提交上来的字节数组。
FileStream fss = new FileStream(fileSavePath, FileMode.Create);
ms.WriteTo(fss);
fss.Close();
ms.Close();
XML没试过,可以试下
string filePath = Request["UpFile"];
//开始上传
//获取要保存的文件信息
FileInfo file = new FileInfo(filePath);
//获取文件扩展名
string fileExtenName = file.Extension;
//重命名文件
string fileNewName = DateTime.Now.ToString("yyyyMMddHHmmss") + fileExtenName;
//保存路径
string fileSavePath = Server.MapPath(@"~\uploadFile\images\lineimages\") + fileNewName;
///真正上传就是从这里开始,这是ASP.NET,记得winform也是一样的
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
//把文件流中转化成字节数组
byte[] imageBytes = new byte[(int)fs.Length];
fs.Read(imageBytes, 0, imageBytes.Length);
fs.Close();
MemoryStream ms = new MemoryStream(imageBytes);//定义并实例化一个内存流,以存放提交上来的字节数组。
FileStream fss = new FileStream(fileSavePath, FileMode.Create);
ms.WriteTo(fss);
fss.Close();
ms.Close();
XML没试过,可以试下
#9
这个方法不行吧。filestream只认服务器路径
#10
楼主你是用的哪个方法搞定实现的啊..??