|
Hi dan!
I am sorry I forgot to mention that the message is shown in a typical message box and it has no details below this message.
|
|
|
|
|
Hallo!
has someone tried the minihttpd?
I did and it working fine sofar from my PocketLOOX.
But is I tried to download from a iPAQ it doesn't work?
does soneone have any sugestion for me?
thanks you
sayangoin
|
|
|
|
|
Hi!
You should ask this question in the comments section of the article itself, the generic C# forum isn't the right place.
Regards,
mav
|
|
|
|
|
ok got a similar problem to earlier post but im trying to get images
this is what ive got
if (contentType.StartsWith("image/"))
{
byte[] imageBuffer = new byte[reader.BaseStream.Length];
reader.BaseStream.Read(imageBuffer, 0, (int)reader.BaseStream.Length);
Debug.WriteLine("Sending " + contentType + " back to client");
this.m_socket.Send(imageBuffer);
}
but this is not good beacause the underlying stream doesnt support this operation.
the problem i am trying to solve is this. my application is a proxy for browsing http, all is good except when i encounter an image tag like
|
|
|
|
|
What is your "reader" object's type? What is the underlying stream? I highly doubt that the underlying stream doesn't support the Read operation.
Picture a huge catholic cathedral. In it there's many people, including a gregorian monk choir. You know, those who sing beautifully. Then they start singing, in latin, as they always do: "Ad hominem..."
-Jörgen Sigvardsson
|
|
|
|
|
It is using WebResponse stream. i think it was the peek operation it doesnt support.
regards,
g00fy
|
|
|
|
|
I can't see where you used the peek operation in your code, and it is highly unlikely that the stream wouldn't support .Read. A bit more explanation of how your doing things would help.
|
|
|
|
|
sorry here is the entire code.
internal void Run()
{
string message = "";
string uriString;
Encoding encoding;
try
{
byte[] read = new byte[1024];
int bytes = this.m_socket.Receive(read);
message = Encoding.ASCII.GetString(read);
if (bytes < 1)
{
return;
}
HttpHeaderParser parser = new HttpHeaderParser(message);
uriString = parser.RequestUri;
Debug.WriteLine("Received request to page: " + uriString);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uriString);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Debug.WriteLine("Received response ... OK");
try
{
encoding = Encoding.GetEncoding(response.ContentEncoding);
}
catch
{
encoding = Encoding.GetEncoding(1252);
}
WebHeaderCollection headers = response.Headers;
string contentType = headers[HttpResponseHeader.ContentType];
Debug.WriteLine(" ### Content Type: " + contentType);
StreamReader reader = new StreamReader(response.GetResponseStream());
if (contentType.StartsWith("image/"))
{
byte[] imageBuffer = new byte[reader.BaseStream.Length];
reader.BaseStream.Read(imageBuffer, 0, (int)reader.BaseStream.Length);
Debug.WriteLine("Sending " + contentType + " back to client");
this.m_socket.Send(imageBuffer);
}
else
{
Debug.WriteLine("reading page content");
string content = reader.ReadToEnd();
Debug.WriteLine("Content read, length is: " + content.Length);
byte[] buffer = new byte[content.Length + 1];
Debug.WriteLine("Sending " + contentType + " back to client");
int length = encoding.GetBytes(content, 0, content.Length, buffer, 0);
this.m_socket.Send(buffer, length, 0);
}
response.Close();
reader.Close();
this.m_socket.Shutdown(SocketShutdown.Both);
this.m_socket.Close();
}
catch (Exception e)
{
Debug.WriteLine(" ***** Exception: " + e.Message);
}
}
thank you
g00fy
|
|
|
|
|
Hi im trying to concatenate three cells in a database table using this code but when any of the three cells are null the entire name is returned as null im just wondering if anyone knows anyway to solve this or any ideas on how to avoid it. Thanks in advance
select p.firstName + ' ' + p.MiddleName + ' ' + p.LastName as Name
from SquadPlayerMapping spm
join Squad s on s.ID = spm.squadid
join Person p on p.id = spm.playerid
where dateentered <= GetDate()
and dateleft is null
and s.ID = 11
|
|
|
|
|
tadhg88 wrote:
but when any of the three cells are null the entire name is returned as null
That is by design. Any operations you carry out on a NULL value will return NULL. You will have to manually extract each field from the DB, check if they are NULL in your C# program, and accordingly perform the concatenation.
HTH!
Cheers,
Vikram.
http://www.geocities.com/vpunathambekar
Google talk: binarybandit After all is said and done, much is said and little is done.
|
|
|
|
|
IsNull[^]
You select becomes
select ISNULL(p.firstName,'') + ' ' + ISNULL(p.MiddleName,'') + ' ' + ISNULL(p.LastName,'') as Name
from ...
|
|
|
|
|
Hi
I want to set the File Access (e.g. FileAccess.Read
) attribute in my C# program. I found the System.IO.File.SetAttributes() Function but it seems not to be the right thing.
I also do not want to use the FileStream constructor.
Is there another way?
Thanks
|
|
|
|
|
Can you be more descriptive on what "it seems not to be the right thing" means? Keep in mind these are just access level permissions. NTFS will have another level that will alter the behavior.
|
|
|
|
|
I work with a file in my program. But I want to avoid that the file is modified outside of my application by another user. So I thought to make it write protected would be a solution. Do you have another recommendation?
Thanks!
|
|
|
|
|
Hi,
is there an example, how to download a (msi) file from a web-site (via http) to the local harddisk in C#?
Thanks!
Ariadne
|
|
|
|
|
Use HttpWebRequest[^] to issue the request for the MSI file, this will be returned in a HttpWebResponse[^] object. You can then stream the data to the local disk.
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
Thanks Colin,
I did this:
<br />
myReq=HttpWebRequest)WebRequest.Create("http://www.xyz.ch/file.msi");<br />
myResponse = myReq.GetResponse();<br />
ReceiveStream = myResponse.GetResponseStream();<br />
FileStream frStream = new FileStream(ReceiveStream, FileAccess.Read);<br />
FileStream fwStream = new FileStream(Application.StartupPath+"file.msi",FileMode.Create,FileAccess.Write);<br />
But this does not work: ReceiveStream is not System.IO.Stream
Ariadne
|
|
|
|
|
If I recall correctly, you need to pass the ResponseStream to a StreamReader . You can then read the contents of the stream to a byte array and then write the array that to your output file stream. The response stream will tell you how large you need to make the byte array (of course, you can always make it smaller and retrieve the information in chunchs by using multiple reads)
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|
|
Yes Colin, the canonical way works! thanks.
Ariadne
|
|
|
|
|
have you tried the WebClient class?
WebClient w = new WebClient();
w.DownloadFile(address_str,file_str);
//if you want to hold the file only in memory, try
// w.DownloadData() //for parameters check msdn
this is maybe a lot simpler than working with HttpWebRequest objects
best regards
j.
|
|
|
|
|
Yes much more easy! thanks.
I now use this WebClient version
Ariadne
|
|
|
|
|
how do i remove the beggining of a string up to a forward slash "/"?
|
|
|
|
|
string newstring = oldstring.Substring(oldstring.IndexOf('/')+1);
What this basically does:
- find the index of the first occurence of '/' and take the next char (+1)
- take a substring from the original string beginning at the index right after the index of the first backslash
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi.
I have a textbox and it has been setup to look like a textarea.
When I type in text, something like:
AAAAAAAAAAAAAA
AAAAAAAAAAAAAA
BBBBBBBBBBBBBB
BBBBBBBBBBBBBB
CCCCCCCCCCCCCC
CCCCCCCCCCCCCC
I have an insert button and I add it the database. When I display it on a page, then it all looks like:
AAAAAAAAAAAAAAAAAAAAAAAAAAAABBBBBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCCCC
How do I code it so that it displays the break tags on the aspx page? In classic ASP I did it as follows:
Replace(objRs("Description"), Chr(10), Chr(10) & " <br>")
I just need to know how to do this in C#, or if there is a better way to do it.
Regards,
ma se
|
|
|
|
|
Use string.Replace()[^]
My: Blog | Photos
"Man who stand on hill with mouth open will wait long time for roast duck to drop in." -- Confucious
|
|
|
|