public static HttpWebResponse UploadFile(string fname, string postURL) { FileStream fileStream = new FileStream(fname, FileMode.Open, FileAccess.Read); byte[] array = new byte[fileStream.Length]; fileStream.Read(array, 0, array.Length); fileStream.Close(); Dictionary <string, object> dictionary = new Dictionary <string, object>(); dictionary.Add("filename", FileHelper.GetFileName(fname)); dictionary.Add("fileformat", FileHelper.GetFileExtNoIncDot(fname)); dictionary.Add("file", new HttpFormUpload.FileParameter(array, FileHelper.GetFileName(fname), "")); HttpWebResponse result; try { HttpWebResponse httpWebResponse = HttpFormUpload.MultipartFormDataPost(postURL, HttpFormUpload.UserAgent, dictionary); result = httpWebResponse; } catch (WebException ex) { throw ex; } return(result); }
public static HttpWebResponse MultipartFormDataPost(string postUrl, string userAgent, Dictionary <string, object> postParameters) { string text = string.Format("----------{0:N}", Guid.NewGuid()); string contentType = "multipart/form-data; boundary=" + text; byte[] multipartFormData = HttpFormUpload.GetMultipartFormData(postParameters, text); return(HttpFormUpload.PostForm(postUrl, userAgent, contentType, multipartFormData)); }