Click here to Skip to main content
15,892,059 members
Home / Discussions / C#
   

C#

 
GeneralRe: Setting in C# Pin
Keith Barrow6-Nov-10 22:23
professionalKeith Barrow6-Nov-10 22:23 
GeneralRe: Setting in C# Pin
jojoba20116-Nov-10 22:30
jojoba20116-Nov-10 22:30 
GeneralRe: Setting in C# Pin
Keith Barrow6-Nov-10 22:39
professionalKeith Barrow6-Nov-10 22:39 
GeneralRe: Setting in C# Pin
jojoba20116-Nov-10 22:52
jojoba20116-Nov-10 22:52 
GeneralRe: Setting in C# Pin
Keith Barrow6-Nov-10 22:58
professionalKeith Barrow6-Nov-10 22:58 
AnswerRe: Setting in C# Pin
RaviRanjanKr6-Nov-10 23:02
professionalRaviRanjanKr6-Nov-10 23:02 
AnswerRe: Setting in C# Pin
Paul Michalik6-Nov-10 23:13
Paul Michalik6-Nov-10 23:13 
QuestionHttpWebResponse/HttpWebRequest upload image Pin
TAREQ F ABUZUHRI6-Nov-10 9:08
TAREQ F ABUZUHRI6-Nov-10 9:08 
i have prolem with uloadinge image to server
i try to upload image and send data (POST) method a the same time

i use this code
HttpWebResponse response;
Stream resStream;
StreamReader objSR;
CookieContainer cookieContainer = new CookieContainer();
ASCIIEncoding encoding = new ASCIIEncoding();
HttpWebRequest request;
string sResponse;
string postData;
byte[]  data;
string UrlLogin;

//Upload Image Page *****************************************
//**************************************************************

UrlLogin = "http://localhost:63637/whois/test0.aspx";
string uploadfile = "C:\\fax\\pics\\7130570.jpg";
string fileFormName = "userfile";
string contenttype = "image/pjpeg";

postData = "?wm_flag=" + "0";
postData += ("&action=" + "process");
postData += ("&hi=" + "ft");
request = (HttpWebRequest)WebRequest.Create(UrlLogin + postData);
//request.Accept = "*/*";
request.KeepAlive = true;
request.CookieContainer = cookieContainer;
string boundary = "----------" + DateTime.Now.Ticks.ToString("x");
request.ContentType = "multipart/form-data; boundary=" + boundary;
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
request.Method = "POST";
request.AllowAutoRedirect = true;

data = encoding.GetBytes(postData);

StringBuilder sb = new StringBuilder();
sb.Append("--"); sb.Append(boundary); sb.Append("\r\n"); sb.Append("Content-Disposition: form-data; name=\""); sb.Append(fileFormName); sb.Append("\"; filename=\"");
sb.Append(Path.GetFileName(uploadfile)); sb.Append("\""); sb.Append("\r\n"); sb.Append("Content-Type: "); sb.Append(contenttype); sb.Append("\r\n"); sb.Append("\r\n");
string postHeader = sb.ToString();
byte[] postHeaderBytes = Encoding.UTF8.GetBytes(postHeader);

// Build the trailing boundary string as a byte array
// ensuring the boundary appears on a line by itself
byte[] boundaryBytes = Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");

FileStream fileStream = new FileStream(uploadfile, FileMode.Open, FileAccess.Read);
long length = postHeaderBytes.Length + fileStream.Length + boundaryBytes.Length;// +data.Length;
//postData += ("&userfile=" + "C:\\Users\\tareq\\Desktop\\111111.jpg");

request.ContentLength = length;//data.Length;

Stream requestStream = request.GetRequestStream();
requestStream.Write(postHeaderBytes, 0, postHeaderBytes.Length);
byte[] buffer = new Byte[checked((uint)Math.Min(4096, (int)fileStream.Length))];
int bytesRead = 0;
while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
    requestStream.Write(buffer, 0, bytesRead);
requestStream.Write(boundaryBytes, 0, boundaryBytes.Length);

response = (HttpWebResponse)request.GetResponse();
resStream = response.GetResponseStream();
objSR = new StreamReader(resStream);
sResponse = objSR.ReadToEnd();




this code workfinewithout any problem with uploading photo
but my problem with i request.form["wm_flag"] in the server i got error because i must send it as POST and i don't know how to do it ?? please HELP ...
Palestine

QuestionGet min and max color from a range of RGB colors from listbox Pin
pancakeleh6-Nov-10 8:01
pancakeleh6-Nov-10 8:01 
AnswerRe: Get min and max color from a range of RGB colors from listbox Pin
PIEBALDconsult6-Nov-10 8:17
mvePIEBALDconsult6-Nov-10 8:17 
AnswerRe: Get min and max color from a range of RGB colors from listbox Pin
Luc Pattyn6-Nov-10 8:33
sitebuilderLuc Pattyn6-Nov-10 8:33 
AnswerRe: Get min and max color from a range of RGB colors from listbox Pin
pancakeleh6-Nov-10 8:58
pancakeleh6-Nov-10 8:58 
GeneralRe: Get min and max color from a range of RGB colors from listbox Pin
_Erik_6-Nov-10 10:00
_Erik_6-Nov-10 10:00 
GeneralRe: Get min and max color from a range of RGB colors from listbox [modified] Pin
pancakeleh6-Nov-10 19:59
pancakeleh6-Nov-10 19:59 
GeneralRe: Get min and max color from a range of RGB colors from listbox Pin
Dave Kreskowiak7-Nov-10 2:17
mveDave Kreskowiak7-Nov-10 2:17 
QuestionWhat am I doing wrong?? Sending serialized objects with Async Sockets.. [Solved] Pin
Jacob D Dixon6-Nov-10 7:53
Jacob D Dixon6-Nov-10 7:53 
AnswerRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
Jacob D Dixon7-Nov-10 15:25
Jacob D Dixon7-Nov-10 15:25 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
Peter_in_27807-Nov-10 15:31
professionalPeter_in_27807-Nov-10 15:31 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
Jacob D Dixon8-Nov-10 17:56
Jacob D Dixon8-Nov-10 17:56 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
RaviRanjanKr7-Nov-10 16:47
professionalRaviRanjanKr7-Nov-10 16:47 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
Jacob D Dixon8-Nov-10 17:57
Jacob D Dixon8-Nov-10 17:57 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
Member 1841422-Mar-11 22:48
Member 1841422-Mar-11 22:48 
QuestionUSer Control Error Pin
SRJ925-Nov-10 17:19
SRJ925-Nov-10 17:19 
AnswerRe: USer Control Error Pin
OriginalGriff5-Nov-10 22:54
mveOriginalGriff5-Nov-10 22:54 
AnswerRe: USer Control Error Pin
_Erik_5-Nov-10 23:15
_Erik_5-Nov-10 23:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.