I'm having severe trouble with this. I have a function that asks for a stream that is read and returned by an additional function. The stream belongs to a PNG-image that is portrayed as a backgroundimage in a picturebox on the form. This works out fine, but I want to save the stream data in the class streamInfo
in the variable streamData
so that I can later pass it to another function that enables me to upload the stream or rather the picture to a different location of the FTP server. When I pass the stream as an argument I receive the error
Stream not readable
If I try to output the stream data in the console it just says System.Net.FtpdataStream
.
How can I save the returned Stream (preferablly in the class and without converting or encoding it) and later pass it to the other function so that it is still readable and can be passed as an upload argument?
This is the main funtion:
if (content.Contains(box.SelectedItem.ToString()))
{
stream = request_Preview_Image("somePath" + content);
this.imagePreview.BackgroundImage = Image.FromStream(stream);
blitzStream.streamData = stream;
blitzStream.streamName = content;
}
this is the function that's called:
Stream request_Preview_Image(string create)
{
FtpWebRequest ftp = (FtpWebRequest)WebRequest.Create("ftp://someFTP" + create);
ftp.Credentials = someCredentials;
ftp.Method = WebRequestMethods.Ftp.DownloadFile;
FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
try
{
return (Stream)response.GetResponseStream();
}
catch
{
return (Stream)null;
}
}
This is the class:
private class streamInfo
{
public string streamName { get; set; } = null;
public Stream streamData { get; set; }
}
Many thanks!