通过FTP上传CSV文件 [英] upload a CSV file via FTP
问题描述
我想通过我的FTP发送CSV文件,但我的主要方法是抛出以下错误 - 参数1:无法从'void'转换为'System.IO.Stream'
I would like to send CSV file via my FTP but my main method is throwing the following error - Argument 1: cannot convert from 'void' to 'System.IO.Stream'
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("anonymous", "janeDoe@contoso.com");
// Copy the contents of the file to the request stream.
StreamReader sourceStream = new StreamReader(createCSV());
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
CSV方法:
CSV method:
public void createCSV()
{
string constr = ConfigurationManager.ConnectionStrings["#######"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
/// get data
//Download the CSV file.
Response.Clear();
Response.Buffer = true;
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Response.Charset = "";
Response.ContentType = "application/text";
Response.Output.Write(csv);
Response.Flush();
Response.End();
}
}
}
}
}
请咨询进一步。谢谢
Please advice further. Thank you
推荐答案
嗯...
Um...
StreamReader sourceStream = new StreamReader(createCSV());
public void createCSV()
所以你试图有效地做到这一点:
So you are trying to effectively do this:
StreamReader s = new StreamReader(void);
你希望编译吗?
我不确定该代码究竟是做什么的,但是那里甚至没有尝试处理FTP:如果你想要使用FTP,然后开始查看 FtpWebRequest类 [ ^ ]或预建的库,如简单C#FTP类 [ ^ ]
And you expect that to compile?
I'm not sure exactly what that code is meant to do, but there is nothing there that even tries to deal with FTP: if you want to use FTP, then start by looking at teh FtpWebRequest class[^] or a prebuilt library such as Simple C# FTP Class[^]
这篇关于通过FTP上传CSV文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!