dannystommen
March 19th, 2009, 11:19 AM
Hello,
My problem is the next: I have a winform app and a webapp using both the same database. What I now do is the next: using the winform app I save a System.Drawing.Image in the database. I convert the Image to byte[] and the otherway around when I select the image from the database. I show this image in a picturebox.
But the problem is, I cannot show this image in the webapp, which is type of System.Web.UI.WebControls.Image.
I googled to convert System.Drawing.Image to System.Web.UI.WebControls.Image, but for as far I could find, this is not possible.
So I decided to upload the images to the webserver. In the webapp I can not easily say ImageUrl="myimage.bmp".
The problem now is the winform app. I am able to download the image from the server, using the WebClient, but I can't get the uploading part working.
System.Net.WebClient client= new System.Net.WebClient();
client.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\temp\blue.png");
byte[] data = new byte[0];
using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
data = ms.ToArray();
}
byte[] result1 = client.UploadData("http://mydomain.com/Images/blue.png", data);
byte[] result2 = client.UploadFile("http://mydomain.com/Images/blue.png", @"C:\temp\blue.png");
Both UploadData and UploadFile gives WebException: "The remote server returned an error: (405) Method Not Allowed."
My problem is the next: I have a winform app and a webapp using both the same database. What I now do is the next: using the winform app I save a System.Drawing.Image in the database. I convert the Image to byte[] and the otherway around when I select the image from the database. I show this image in a picturebox.
But the problem is, I cannot show this image in the webapp, which is type of System.Web.UI.WebControls.Image.
I googled to convert System.Drawing.Image to System.Web.UI.WebControls.Image, but for as far I could find, this is not possible.
So I decided to upload the images to the webserver. In the webapp I can not easily say ImageUrl="myimage.bmp".
The problem now is the winform app. I am able to download the image from the server, using the WebClient, but I can't get the uploading part working.
System.Net.WebClient client= new System.Net.WebClient();
client.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
System.Drawing.Image img = System.Drawing.Image.FromFile(@"C:\temp\blue.png");
byte[] data = new byte[0];
using (System.IO.MemoryStream ms = new System.IO.MemoryStream()) {
img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
data = ms.ToArray();
}
byte[] result1 = client.UploadData("http://mydomain.com/Images/blue.png", data);
byte[] result2 = client.UploadFile("http://mydomain.com/Images/blue.png", @"C:\temp\blue.png");
Both UploadData and UploadFile gives WebException: "The remote server returned an error: (405) Method Not Allowed."