Click here to Skip to main content
15,949,741 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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'

C#
// 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 method:
C#
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
Posted
Comments
Herman<T>.Instance 4-Feb-15 10:43am    
I guess you need StreamWriter() looking at the line:
Response.Output.Write(csv);

Furthermore you method createCSV has void returntype in stead of a Stream or FileStream object.

1 solution

Um...
C#
StreamReader sourceStream = new StreamReader(createCSV());

C#
public void createCSV()

So you are trying to effectively do this:
C#
StreamReader s = new StreamReader(void);
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[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900