|
WinSolution wrote: div = Convert.ToInt32(textBox1.Text.Trim());
You should use int.TryParse to test if the entered text is a number or not.
Christian Graus
Driven to the arms of OSX by Vista.
"! i don't exactly like or do programming and it only gives me a headache." - spotted in VB forums.
I can do things with my brain that I can't even google. I can flex the front part of my brain instantly anytime I want. It can be exhausting and it even causes me vision problems for some reason. - CaptainSeeSharp
|
|
|
|
|
You may also handle the exception for ptr[0] = ptr[1] = ptr[2] = (byte)((ptr[0] + ptr[1] + ptr[2]) / div);
|
|
|
|
|
[Intro]
To keep the story short, I have created a Download manager creating various simultaneous HttpRequests and downloading the HttpResponses (of the files).
In brief, the relevant code looks somewhat like this...
dRequest = (HttpWebRequest)WebRequest.Create(txtURL.Text);
dRequest.AddRange(dFrom, dTo);
dResponse = (HttpWebResponse)dRequest.GetResponse();
Stream dStream = dResponse.GetResponseStream();
..And of course the download is saved etc etc etc. This all works fine.
[End of Intro]
Today I was told that I should enable compression (from the server side - whenever possible) when downloading the file in order to speed up the download even more... However, I have no idea how this works or how this can be achieved?
I am not asking for someone to do the code for me (although any examples are appreciated), but I would like to know how this can be achieved / how the system works, or what to search for, in order to achieve this?
Huge thanks!
|
|
|
|
|
|
Please go through the following article which contains exactly what you need
Using HTTP Compression for Faster Downloads[^]
If you need to increase the speed further then you may use the below code which actually deals in sockets and increases the speed to many folds when parallel downloading is going on.
public class MyWebResponse
{
public MyWebResponse()
{
}
public void Connect(MyWebRequest request)
{
ResponseUri = request.RequestUri;
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint remoteEP = new IPEndPoint(Dns.Resolve(ResponseUri.Host).AddressList[0], ResponseUri.Port);
socket.Connect(remoteEP);
}
public void SendRequest(MyWebRequest request)
{
ResponseUri = request.RequestUri;
request.Header = request.Method + " " + ResponseUri.PathAndQuery + " HTTP/1.0\r\n" + request.Headers;
socket.Send(Encoding.ASCII.GetBytes(request.Header));
}
public void SetTimeout(int Timeout)
{
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, Timeout * 1000);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, Timeout * 1000);
}
public void ReceiveHeader()
{
Header = "";
Headers = new WebHeaderCollection();
byte[] bytes = new byte[10];
while (socket.Receive(bytes, 0, 1, SocketFlags.None) > 0)
{
Header += Encoding.ASCII.GetString(bytes, 0, 1);
if (bytes[0] == '\n' && Header.EndsWith("\r\n\r\n"))
break;
}
MatchCollection matches = new Regex("[^\r\n]+").Matches(Header.TrimEnd('\r', '\n'));
for (int n = 1; n < matches.Count; n++)
{
string[] strItem = matches[n].Value.Split(new char[] { ':' }, 2);
if (strItem.Length > 0)
Headers[strItem[0].Trim()] = strItem[1].Trim();
}
// check if the page should be transfered to another location
if (matches.Count > 0 && (
matches[0].Value.IndexOf(" 302 ") != -1 ||
matches[0].Value.IndexOf(" 301 ") != -1))
// check if the new location is sent in the "location" header
if (Headers["Location"] != null)
{
try { ResponseUri = new Uri(Headers["Location"]); }
catch { ResponseUri = new Uri(ResponseUri, Headers["Location"]); }
}
ContentType = Headers["Content-Type"];
if (Headers["Content-Length"] != null)
ContentLength = int.Parse(Headers["Content-Length"]);
KeepAlive = (Headers["Connection"] != null && Headers["Connection"].ToLower() == "keep-alive") ||
(Headers["Proxy-Connection"] != null && Headers["Proxy-Connection"].ToLower() == "keep-alive");
}
public void Close()
{
socket.Close();
}
public Uri ResponseUri;
public string ContentType;
public int ContentLength;
public WebHeaderCollection Headers;
public string Header;
public Socket socket;
public bool KeepAlive;
}
2)
|
|
|
|
|
Thanks mate! It appears to be just what I wanted... Looks more complex then the methods I'm currently using but I guess that's the way to go... Thanks a lot
|
|
|
|
|
You welcome buddy
|
|
|
|
|
Hi,
I am pretty new to developing in InfoPath and SharePoint. I have the requirement to extract repeating table data from an InfoPath form using web part (written in C#).
I have been looking into how I might go about doing this but I don't seem to have come up with a solution.
I have tried getting the document as an XML document but it will not let me open it in the web part and claims I don't have the correct permissions, even though i have full permissions across the whole site (including on the document library)
Could anyone point me in the right direction or offer any advice?
Many thanks in advance,
Luke
|
|
|
|
|
For a label control i dynmically changed the font and color of the text and then i stored those values in the database(access) and i want to apply the values stored in the database to other labels. How to apply those stored values to other labels from the database. I retrieved those values from database i got the values as string , then how to apply these string values to change the color of the label.
|
|
|
|
|
praveenkumar_vittaboina wrote: i got the values as string
Storing colors should result into a numeric value.
look at the 'color.toargb' and 'color.fromargb' functions.
Or 'color.toknowncolor' and 'color.fromknowncolor' functions
|
|
|
|
|
the project which i am doing is windows based project . In that i need to generate some reports , so i did that with crystal reports and then i created a setup file and then i installed in another system, then i am getting the exception . After that i removed crystal reports from my project and again i installed the setup file , then its working fine. I want to know how to include the reports.
|
|
|
|
|
Without knowing more about the error you get I think you need to install the crystal report framework.
You can include this into your .net setup.
Google for merge modules on how to do that.
The crystal reports site has the download for their merge modules somewhere but I can't find the link right now.
|
|
|
|
|
Hi everyone,
I'm writing a little application and I've hit a bit of a problem.
part of the program uses the registry to store certain things. I have no problem writing or reading a key. But I need to be able to check the key exists, if it does do this, if not write the key.
Here's the code I'm currently using:
using Microsoft.Win32;<br />
RegistryKey MyRegKey = Registry.LocalMachine.OpenSubKey("software\\MyApp\\SaveData");<br />
if (MyRegKey != null)<br />
{<br />
string OptCurrency = MyRegKey .GetValue("Currency").ToString();<br />
}<br />
else<br />
{<br />
RegistryKey CreateMyRegKey = Registry.LocalMachine.CreateSubKey("software\\MyApp\\SaveData");<br />
CreateMyRegKey .SetValue("Currency", 0);<br />
string OptCurrency = "0";<br />
}<br />
MyRegKey.Close();
This is fine if the key exists, but doesn't recognise if it does not, and runs through the if rather than the else.
Any help would be greatly appreciated
Many thanks
Martin
|
|
|
|
|
I am not sure that I understand this.
Are you saying that if software\\MyApp\\SaveData doesn't exist, the if part of your code executes?
BTW: if you surround your code snippet with <pre></pre>, rather than <code></code>, it will allow you to retain the formatting and make it easier for others to read. (use the 'code block' widget, not the 'inline code' one).
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
the other way around, if that key doesn't exist run the else part to create the key.
|
|
|
|
|
I realise that is what you intend to happen. But your OP indicated the reverse.
This is fine if the key exists, but doesn't recognise if it does not, and runs through the if rather than the else.
indicates to me that the if block gets executed regardless of whether the key exists or not.
Perhaps you might try rewording your question, to differentiate what you want to happen from what currently happens.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Currently
It does run through the if regardless of whether the key exists or not. The way the code is at the moment (some changes have been made to the previous post) the key will get created if it does not exist. I can then make a change in the options of my application and apply them which saves the change to their respective keys.
Then when I close the program and re-open it, the keys are reset back to the default because the code is running through the wrong part of my if statement and overwriting the key.
Intended
I would like it to be able to tell if the key exists, if it does not, create it, if it does, copy the value of each key into the defined global variables. So that program can use these values wherever necessary.
I'll post the altered code if you need.
I hope this clears it up.
Thanks
|
|
|
|
|
I do not use the registry any more, or very rarely, so I have had to go back and look at some of my old code.
The only obviously different things that I used to do is as below.
string myAppSaveDataSubKey = @"software\MyApp\SaveData"; <=== use a variable. saves having to keep typing it in and possible typos
using (RegistryKey MyRegKey = Registry.LocalMachine.OpenSubKey(myAppSaveDataSubKey)) <== using 'using' saves having to remember 'close'
{
if (MyRegKey == null) <=========== Check == null instead of != null
{
RegistryKey CreateMyRegKey = Registry.LocalMachine.CreateSubKey(myAppSaveDataSubKey);
CreateMyRegKey.SetValue("Currency", 0);
string OptCurrency = "0";
}
else
{
string OptCurrency = MyRegKey.GetValue("Currency").ToString(); <== you need to load OptCurrency anyway so don't 'else' it
}
}
which used to work OK for me.
The only other thing you might consider is to use CreateSubKey instead of OpenSubKey . This has the advantage of creating the subkey if it doesn't exist, and simply opening it for writing if it does.
Hope some of this is useful.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thanks for the suggestion, I'll have to look at it tomorrow.
I'll let you know how I get on.
Thanks alot for your support
Martin
|
|
|
|
|
I've finally sorted it!
I used some suggestions from your last post which helped. But I decided to tackle it from a different angle, eventually i came up with doing a valueCount
If (Count != 3)
{
create the keys
}
then copy values of each.
Works perfectly.
Thanks alot for your support Henry
Best regards
Martin
|
|
|
|
|
Hi friends,
I have a checkedlistbox control on my windows form. Now when Application runs, every item is unchecked and user checks the items as per his choice. I want that - next time when user runs the application - checkedlistbox should be loaded with the same items checked. Meaning no need to recheck those values.
How do i do that?
many thanks,
Jeet
|
|
|
|
|
havejeet wrote: How do i do that?
Store the checked items in a persistent store (database, file).
Read the stored values and load them when your form loads.
Manas Bhardwaj
Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.
|
|
|
|
|
You might use a file or the registry for storing your application settings.
It is a crappy thing, but it's life -^ Carlo Pallini
|
|
|
|
|
Hello Experts!!
I am using following code inwhich instead of current value it takes null.I am using it at cell leave event of datagrid.
<pre>int ind = dataGridView1.CurrentRow.Index;
if (call == 1 ||call==2)
{
arr[x++] = (string)dataGridView1.Rows[ind].Cells[1].Value; //Error here
call++;
}
|
|
|
|
|
Let me turn my mind reader on...
trying to read error...
dense object detected...
error: can't read mind, shutting down now.
What error do you get?
What's the code supposed to do?
What does it do?
And what is your question?
|
|
|
|