views:

78

answers:

2

Hi,

i want to upload image to IIS server using c# web service.I have written the web method for this as follows...

[WebMethod]

public string UploadFile(byte[] f, string fileName) { try { MemoryStream ms = new MemoryStream(f);

   FileStream fs = new FileStream(System.Web.Hosting.HostingEnvironment.MapPath
   ("~/TransientStorage/") +fileName, FileMode.Create); 

   ms.WriteTo(fs); 

   ms.Close();
   fs.Close();
   fs.Dispose(); 

   return "OK";
}
catch (Exception ex)
{
    // return the error message if the operation fails
    return ex.Message.ToString();
}

}

here the web method is taking argument as byte[] .I have convert the sdcard image to byte[] but when i am passing it as an URL paramete it is not working .I have also tried by converting the byte[] array to base64 strig still it is not working.

Can any one tell me how to upload image to IIS server using c# web service.

Thanks..

+1  A: 

You'll need to POST it to the server, setting the content type and including the byte array as the body of the post.

See here for an example of doing it from C# and here for an example for android.

Andy Robinson
Thanks a lot Andy...the code is working fine but after uploading i can't find the destination folder of the uploaded images. i am running php on IIS server.
Sujit
Glad it helped. The uploaded file should be in the web service application folder under the TransientStorage folder? Does the folder exist? Are you getting any errors returned? Are you able to debug the web service? I'm also a little bit confused where php comes into this setup?
Andy Robinson
A: 

it for delete image

string all_picture = ds100.Tables[0].Rows[i][0].ToString(); { System.IO.File.Delete(System.IO.Path.Combine(path, all_picture)); }

azeem
what is this...please give some valid answer
Sujit