Sign in
or
Join FriendFeed
FriendFeed
is the easiest way to share online.
Learn more »
Join FriendFeed
Cameron McGrane
Brian Grinstead » Blog Archive » Multipart Form Post in C# -
http://www.briangrinstead.com/blog...
August 9, 2010
from
delicious
-
Comment
-
Like
-
Share
// Read file data FileStream fs = new FileStream("c:\\people.doc", FileMode.Open, FileAccess.Read); byte[] data = new byte[fs.Length]; fs.Read(data, 0, data.Length); fs.Close(); // Generate post objects Dictionary<string, object> postParameters = new Dictionary<string, object>(); postParameters.Add("filename", "People.doc"); postParameters.Add("fileformat", "doc"); postParameters.Add("file", new FormUpload.FileParameter(data, "People.doc", "application/msword")); // Create request and receive response string postURL = "
http://localhost
"; string userAgent = "Someone"; HttpWebResponse webResponse = FormUpload.MultipartFormDataPost(postURL, userAgent, postParameters); // Process response StreamReader responseReader = new StreamReader(webResponse.GetResponseStream()); string fullResponse = responseReader.ReadToEnd(); webResponse.Close(); Response.Write(fullResponse); -
Cameron McGrane