views:

83

answers:

2

hi there how can i send a file via web service in my site same as gmail attachments in c# and asp.net

A: 

Just create a Web Method that accepts two parameters: a byte array and a filename.

Inside the method, simply open a FileStream to a new file with the filename and write the contents of the byte array to the file. An overly simple example method (without Web Service decorations since you never specify what Web Service framework you're using):

public void WriteBytesToFile(string filename, byte[] contents)
{
    using(FileStream fs = 
        new FileStream("C:\\UpdloadDir\\"+filename, FileMode.Create))
    {
        fs.Write(contents, 0, contents.Length);
    }
}

Without more details, that's about as specific as I can get. Remember, we're not code monkeys. We're not going to write all of your code for you. If you have some code already, post it and we'll try to help you to get it to work.

Justin Niessner
please write a simple example for this thanks a lot
DarkMan
@user422944, did you miss the `we're not code monkeys. We're not going to write all of your code for you. If you have some code already, post it and we'll try to help you to get it to work.` part of Justin's answer? At least **try** writing it yourself =)
Rob
@user422944 - @Rob got it right. I'm not going to write all your code for you. I did add an overly simplified example to demonstrate purpose. Keep in mind, though, that the code I posted will cause issues.
Justin Niessner
A: 

If you're trying to send email attachments, investigate System.Net.Mail. Scott Guthrie has a good introduction on his blog.

Dour High Arch