views:

38

answers:

3

Hi,

I am loading an image using

OpenFileDialog open = new OpenFileDialog();

After I select the file, "open" is populated with several items, including the path.

Now I would like to load the file into a filestream (or something similar) to be sent via a webservice... is this possible?

thanks

A: 

You can open the file with FileStream:

FileStream file = new FileStream("path to file", FileMode.Open);

You can then pass this through to the web service http context Response.OutputStream property. You will still need to set the correct mime type and various headers, but this works well:

HttpContext.Current.Response.OutputStream = file;

Having said that, the easiest way to send a file from a web service (or web app) is to use the Response.WriteFile method:

Response.WriteFile("Path To File");
Oded
A: 

Yes it is possible to create an image

var img = Image.FromFile(/*path*/);

or into a stream

var file = new FileStream("path to file", FileMode.Open);

But hot it should be send it is up to You to decide

sendToWs(img)

Vash
if the image will be a bitmap, will it be saved in a bitmap? or if it is a jpeg, fill it be saved in a jpeg, and so on?
mouthpiec
Image is an abstract class that provides functionality for the Bitmap and Metafile. For saving image You use the satatic method save Image.Save(path,format) where format is form ImageFormat
Vash
+1  A: 

try this:

byte[] buff = System.IO.File.ReadAllBytes(open.FileName);
System.IO.MemoryStream ms = new System.IO.MemoryStream(buff);
Arash
is it possible to recreate the document from buff?
mouthpiec
i managed to convert to bitmap by using the normal "new Bitmap()"constructor
mouthpiec