|
That was my fear but you are right, it looks like the only way to do it. What I might do is add my own identifier at the beginning of the file so that I only have to read the first several bytes to check and if they are not there then I know it is not encrypted.
Thanks for all your help.
Russell
|
|
|
|
|
Yep. However, whatever the byte sequence is that you will choose as the "encrypted" flag, it may happen to be present in the original file unless you restrict yourself to a subset of all possible files.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Correct.. I would look for something really obscure and low in probability but yes it could come up.
|
|
|
|
|
you can only reduce the odds, so even with your header check you'll still have to do appropriate error checking on the decrypt stage. Detecting most errors without attempting a decrypt will significantly speed handling of bad files so it's still a good idea.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
Hello,
I'm building a photo editor in C#.
I'm wondering how can I know the compression rate for an existing picture like JPG or PNG?
Thank you very much,
Yasa
|
|
|
|
|
Hi,
you can set the compression rate when saving an image using an ImageCodecInfo object; however I don't know how you can get the information for an existing image.
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
Hi
I have used the following code for the client server communication.The start() starts the server and calls the SenMessage() to send the message to the server.This method takes as input the port number of the server that has started.
It works fine.Suppose i start 2 servers, then both servers are calling the SendMessage().In this case one server communicates properly.For the 2nd one it says that the existing connection is closed.
I think that when the 2nd server starts it should call the sendMessage() with some time delay.I hope that it work then.But im not sure how to do it.Please help me with this.<pre>private void Start_Click(object sender, EventArgs e)
{
//int n;
//label1.Text = "Enter the value of n:";
String n2, n1, n3, n4;
n1 = lb4.Text;
n2 = lb5.Text;
n3 = lb6.Text;
n4 = lb7.Text;
ProcessStartInfo si1,si2,si3,si4;
if (cb.Checked && lb4.Text!="")
{
si1 = new ProcessStartInfo(n1);
proc = Process.Start(si1);
proclist.Add(proc);
String portno1 = n1.Substring(18, 5);
listBox1.Items.Add(portno1);
pno1=Convert.ToInt32(portno1);
SendMessage(pno1);
}
if (cb1.Checked && lb5.Text!="")
{
n2 = lb5.Text;
si2 = new ProcessStartInfo(n2);
proc = Process.Start(si2);
proclist.Add(proc);
String portno2 = n2.Substring(18, 5);
int pno2 = Convert.ToInt32(portno2);
SendMessage(pno2);
}
}
public void SendMessage(int portnumber)
{
try
{
UdpClient client = new UdpClient("127.0.0.1", portnumber);
listBox2.Items.Add("Connected");
Byte[] data = new Byte[256];
String snd = "hello";
data = Encoding.ASCII.GetBytes(snd);
IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), portnumber);
int n = client.Send(data, data.Length);
listBox2.Items.Add("Sent...");
listBox2.Items.Add("Message received from {0}:");
listBox2.Items.Add(ipep.ToString());
Byte[] received = new Byte[512];
received = client.Receive(ref ipep);
String dataReceived = System.Text.Encoding.ASCII.GetString(received);
listBox2.Items.Add(dataReceived);
client.Close();
//}
}
catch (Exception e)
{
listBox2.Items.Add("An Exception Occurred!");
listBox2.Items.Add(e.ToString());
}
}
|
|
|
|
|
hi,
i have a little problem with the following Query:
string str_Verlaufdate = "'" + p.Verlauf_date.Month + "/" + p.Verlauf_date.Day + "/" + p.Verlauf_date.Year + "'";
DataRow[] dr2 = this.dataNet.Tables["Verlauf"].Select("BehID = '"+v[0].ToString()+"' and Date = "+str_Verlaufdate);
I don´t get any result, but there exist a lot of records that match to this date in the database!
|
|
|
|
|
How are your dates stored?
If they are stored with time (3/3/2009 11:12:13) then you wont get any results.
try entering your query in sql server and see what you get
you can also try something like this
string str_Verlaufdate = "'" + p.Verlauf_date.Month + "/" + p.Verlauf_date.Day + "/" + p.Verlauf_date.Year + "%'";
DataRow[] dr2 = this.dataNet.Tables["Verlauf"].Select("BehID = '"+v[0].ToString()+"' and Date LIKE "+str_Verlaufdate);
|
|
|
|
|
yes, they are stored with time!
But when I change the string in this way I get an syntax error:
string str_Verlaufdate = "'" + p.Verlauf_date.Month + "/" + p.Verlauf_date.Day + "/" + p.Verlauf_date.Year + " 00:00:00'";
I don´t know, how the format of the string has to look like.
|
|
|
|
|
When I have to search by dates with times I do a 'from date' and a 'to date' because of the time issues. The from date should be the date with a time of midnight and end date would have a time of 1 second before midnight.
For example, if I wanted everything from April 1 through April 7 I would search for:
2009/04/01 00:00:00 through 2009/04/07 23:59:59
|
|
|
|
|
look at your table data and see what format it is and try something like this
string str_Verlaufdate = "'" + p.Verlauf_date.ToString("mm/dd/yyyy HH:mm:ss") + "'";
or some other format
do some research here[^]
|
|
|
|
|
thanks a lot,
this link solved my problem
|
|
|
|
|
Now, forget everything you just learned and do it the correct way using parameterized queries[^] instead. If you did that first, this would never have been a problem.
|
|
|
|
|
Hear hear!
There's no substitute for doing it the right way.
|
|
|
|
|
Good morning.
I am trying to create a verification class to test for special characters (not including *) when a user types in a text box. I will be running this off of the textbox keydown (or change) method.
So far I have the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace WindowsFormsApplication1
{
class Verification
{
public bool Verify(String strChar)
{
bool InvalidChar = false;
int NumValue = 0;
char[] charArray = strChar.ToCharArray();
foreach (char c in charArray)
{
NumValue += (Convert.ToInt16(c) + 128);
if (NumValue == 42) //ASCII * character
{
InvalidChar = true;
break;
}
else if (NumValue < 65 && NumValue > 90) //ASCII A-Z characters
{
InvalidChar = true;
break;
}
}
return InvalidChar;
}
}
}
I was advised to stay away from Substrings. What is the best method to accomplish this verficiation?
Thank you,
WHEELS
|
|
|
|
|
Regex, or if you want to loop through all of the chars in the string the Char[^] class has a bunch of functions like IsLetter , IsDigit , etc that should help you.
|
|
|
|
|
|
|
hi there!
I want to know if is possible to print the dataTable or a data from datagridview, I was searching 2 -3 days for this thing, but without any success. Every help will be appreciated. thanks in advance, Laziale
|
|
|
|
|
As far as i know, as with all printing you need to do all the work yourself. there is certainly no built in function to print a data table. I assume you must have come across alot to do with printing so start there, but as i say you will have to draw all the info you want to a graphics class instance which is what you will be printing
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
You can search for DataGridView Printer (I used one before) here on CP, if that's your question
|
|
|
|
|
I have a test
if (element.Value.ToString().ToLower() == "home owner")<br />
{<br />
summaryHomeOwnerTextBox.Text = "Yes";<br />
}
How can I test to see with the string "home owner" is contained within element.Value.ToString().ToLower() please?
|
|
|
|
|
too lazy to read up on String class?
Luc Pattyn [Forum Guidelines] [My Articles]
- before you ask a question here, search CodeProject, then Google
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get
- use the code block button (PRE tags) to preserve formatting when showing multi-line code snippets
|
|
|
|
|
or even use the Intelisense of an IDE, there all pretty self explainitory methods and functions lol
but hey, as im sure you know already, there are alot of people on these forums that just are'nt cut out for this kind of 'hard' work
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|