Just when the internship encountered a problem: Upload the file URL has a specific format restrictions, you need to format the header information, to upload the success. Check the data when it was like a Java version, C # code affixed.
//uploadfile: Upload file name Groupid:guid Public stringFileUpload (stringUploadFile,stringgroupId) { //reads a block of bytes from the stream and writes the data to the given bufferFileStream FileStream =NewFileStream (UploadFile, FileMode.Open, FileAccess.Read); byte[] Buffer=NewByte[filestream.length]; FileStream.Read (Buffer,0, Convert.ToInt32 (filestream.length)); //Boundary Setting stringBoundary ="----------"+ DateTime.Now.Ticks.ToString ("x"); stringFileName =Path.getfilename (UploadFile); stringNameonly = filename.substring (0, Filename.lastindexof (".")); Dictionary<string,string> Params =Newdictionary<string,string>(); Params.add ("name", FileName); Params.add ("groupId", groupId); Params.add ("Appmodule","Portal"); Params.add ("FilePath",""); Params.add ("thumbnail","true"); Params.add ("Storetype","1"); Params.add ("property1",""); Params.add ("Property2",""); Params.add ("Property3",""); Params.add ("Property4",""); Params.add ("property5",""); Params.add ("Flag","false"); StringBuilder SB=NewStringBuilder (); //Send required Fields foreach(keyvaluepair<string,string> paraminchParams) {SB= sb. Append ("--"); SB=sb. Append (boundary); SB= sb. Append ("\ r \ n"); SB= sb. Append ("content-disposition:form-data; name=\ ""+ param. Key +"\ "\r\n\r\n"); SB=sb. Append (param. Value); SB= sb. Append ("\ r \ n"); } //the file to sendSB = sb. Append ("--"); SB=sb. Append (boundary); SB= sb. Append ("\ r \ n"); SB= sb. Append ("content-disposition:form-data; name=\ ""+ Nameonly +"\ "; filename=\""+ FileName +"\ "\ r \ n"); SB= sb. Append ("content-type:application/octet-stream\r\n\r\n"); byte[] data =Encoding.Default.GetBytes (sb.) ToString ()); byte[] End_data = Encoding.Default.GetBytes (("\r\n--"+ Boundary +"--\r\n")); Uri URI=NewUri ("Upload file Address"); HttpWebRequest Webrequset=(HttpWebRequest) webrequest.create (URI); Webrequset.contenttype="multipart/form-data; boundary="+boundary; Webrequset.method="POST"; //Length Properties: Header + file stream + tail length LongLength = data. Length + buffer. Length +End_data. Length; Webrequset.contentlength=length; Stream Requeststream=Webrequset.getrequeststream (); //writes the stitched data and the file streamrequestStream.Write (data,0, data. Length); requestStream.Write (Buffer,0, buffer. Length); requestStream.Write (End_data,0, End_data. Length); //Get return informationWebResponse responce =Webrequset.getresponse (); Stream Responestream=responce. GetResponseStream (); StreamReader SR=NewStreamReader (Responestream); returnSr. ReadToEnd ();}
C # uploading files with HttpWebRequest custom header information