|
Event: DataGrid1_MouseDown or DataGrid1_MouseUp
method: Grid1.Rows[0].Columns[0].Value.ToString()==""
ok,understand? so easy ,my english is not very good ,so i can only do my best to help u
|
|
|
|
|
Firstly you need to make it clear if it is a DataGrid or a DataGridView that you are using. They are two different controls, and which one you are using will make a difference to the answer.
I am going to give you an answer based on two assumptions, that it is in fact a DataGridView , and the Column is called 'ID'.
Assuming that you can identify the row selected, hint - research DataGridView.CurrentRow , and have it assigned to a field:DataGridViewRow selectedRow = dataGridView1.CurrentRow .
string idString = selectedRow.Cells["ID"].Value.ToString();
The Point about the two types of grid is important, otherwise you get no answers, or worse you spend ages following a totally wrong answer.
Good luck!
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.”
|
|
|
|
|
Thanx all the guys who helped me out !!!
finally with ur help found it out !
DataGridViewRow SelectedRow = new DataGridViewRow();
SelectedRow = GrammarGrid.CurrentRow;
SelectedGrammarID = Convert.ToInt32(SelectedRow.Cells["GrammarID"].Value);
|
|
|
|
|
Hello all,
I have written a simple application that allows me to encrypt / decrypt files using AES256 encryption. This part works. However, when using wildcards for decryption such as *.doc if you attempt to decrypt a file that was not previously encrypted a Crypto exception is thrown regarding invalid data length.
Is there a way to detect if a file is encrypted or not? I have searched and all I can find is the option of setting the encrypted attribute but this requires using the windows api and I wanted to avoid this.
Thanks for your help.
Russell
|
|
|
|
|
Every encryption has an identifier, once you know the identifier and its offset(oftenly at 0x0) you can know what type of encryption it is then you need to decryt it using its format.
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87֦ʻ6ϣN8ȤBcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKQUFK[M`UKs*$GwU#QDXBER@CBN%
R0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-iTV.C\y<pjxsg-b$f4ia>
-----------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I don't think so. AFAIK, the .net framework doesn't support this apart from the method you didn't want to do. Something you could try though - try to decrypt it. If it throws an exception, you know it wasn't encrypted to start with. Something like this
bool IsEncrypted(string file)
{
try
{
return true;
}
catch
{
return false
}
finally
{
}
}
|
|
|
|
|
Thanks for your replies, however the encryption / decrption part works fine. I have a setup like so:
for each (File......)
try {
load file into a byte array
try and decrypt data in byte array
catch (Exception ex)
{
Oh no, failed to decrypt..
}
When I try to decrypt the file and it fails the exception is thrown and I am then exited from the app. There is no way to get back to the for each loop. I am hoping there is some command or routine that I can use that would enable me to look for something to determine if it is encrypted.
I thought about a header but I am using salt which randomizes the first 4 bytes.
Thanks
Russell
|
|
|
|
|
First, use the code block formatting on code samples.
Second, if your code's written like this (had to insert a few extra }'s), unless you have a throw statement inside the catch block the exception shouldn't break the loop. That should only happen if the entire loop is inside a try/catch block instead of each iteration of it.
for each (File......)
{
try
{
load file into a byte array
try and decrypt data in byte array
}
catch (Exception ex)
{
Oh no, failed to decrypt..
}
}
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
|
|
|
|
|
My 2 cents: I would try to catch a specific exception, instead of any, because an IOException could happen, which would not necessarily mean the file is not encrypted.
|
|
|
|
|
Hi,
a simple solution would be to change the filename, preferably by appending a new extension; that way you now a decrypt is necessary, which would decrypt and remove the added extension.
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
|
|
|
|
|
Yes I thought about that, but it defeats the purpose of my app, and it is too easy for a user to change the filename to something else and then I am back to stage 1 again.
|
|
|
|
|
The main goal of a file extension is to indicate which program(s) can open your file; as long as a .doc file is custom-encrypted, Word won't be able to decrypt it, your own decryptor can, so it makes perfect sense to use a special file extension.
A user can always change filename parts; if he changes .doc into .xls things will go wrong too.
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
|
|
|
|
|
The only way to tell is to try and decrypt the file. WHen you get the exception, handle it appropriately and you've got your answer as to if the file is encrypted or not. There's really no other way to tell.
|
|
|
|
|
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[^]
|
|
|
|