|
From a windows application form I need to print a ticket from a special ticket printer. that ticket includes a 2D barcode which is a string of all the information about a customer. I need to encrypt it and get as a byte array so I use Cryptoservices and done that. to concatenate that data with other data I've done something like this
System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
string str = System.Text.Encoding.ASCII.GetString(b);
So printing part is working fine. But when I scan the barcode and try to get it back to byte array like this,
byte[] b = System.Text.Encoding.ASCII.GetBytes(data);
Then my array size gets smaller and when I try to decrypt it it throws an error saying that invalid length of string.
can anybody help me.
|
|
|
|
|
You can't use ASCII encoding to get the bytes as a string. It only support seven bit character codes, which means that any byte that is between 128 and 255 is replaced by a question mark.
Actually, you shouldn't use any text encoding at all to turn arbitrary bytes into text. Most encodings does't have a character for every possible byte value. Text encodings are used to turn text into bytes and back, not the other way around.
You have to encode the bytes in a different way. You can for example use base64 encoding:
string str = Convert.ToBase64String(b);<br />
<br />
byte[] b = Convert.FromBase64String(str);
---
single minded; short sighted; long gone;
|
|
|
|
|
when I use base64 its working fine. But i want to optimise the space taken by the barcode. I tried hex conversion and that also works fine. and then the size of the barcode is smaller. I want to make it much smaller.
|
|
|
|
|
Base64 puts 6 bits of data in each character, which only gives an overhead of 33%. That's the most compact way that you can easily represent binary data as text.
Hexadeximal representation only puts 4 bits of data in each character, giving an overhead of 50%.
Even if you find some complicated conversion that can squeeze almost 8 bits of data in each character, that is only about 30% better than base64. If you want to make the string substantially shorter, look at what the data represents and see if you can remove any unused parts of it.
---
single minded; short sighted; long gone;
|
|
|
|
|
I have a datatable named EmployeeDT. I am using hastable to store data. I want to to take an employeeID of EmployeeName from data table When i select Employee name in the combobox and add to HashTable.
But i am Binding only EmployeeName.So how can i get Emplyee Id to add to Hash Table?
I am binding data to combobox using this method
foreach(DataRow drow in EmployeeDT.Rows)
{
cboemployee1.Items.Add(drow["Name"].ToString().Replace("\"","\'"));
cboemployee2.Items.Add(drow["Name"].ToString().Replace("\"","\'"));
cboemployee3.Items.Add(drow["Name"].ToString().Replace("\"","\'"));
}
From this code how can i add key to the hash table
|
|
|
|
|
Please don't repost problems so soon after you've posted them before.
I notice that you've been presented with an answer and that you have chosen to ignore this. This site isn't for us to do your work for you.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
The other thing is, don't use 'Urgent' in the subject line.
God Bless,
Jason
I am not perfect but I try to be better than those before me.
So those who come after me will be better than I am.
|
|
|
|
|
am developing application in ASP.Net with C#. i am using button for FileOpenDialog to browse any image from hard drive as follows
openFileDialog1.ShowDialog();
string s = openFileDialog1.FileName;
textBox6.Text = s;
problem is:
i want the browsed image to be copied in local hosti.e,""C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg"
i have the follwing idea in mind
File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg");
or
File.Copy(s.Substring(13,s.Length-13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg");
but i dont want to existing image to be overwrite, i want all images to ve saved in local host
can anyone sugesst me what to do?
|
|
|
|
|
If you use File.Copy("C:\\Inetpub\\wwwroot\\15 WebSite\\images\\1.jpg", "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\xyz.jpg");
it will throw IOException if the destination already exists so you should check that before you start copying. What so you want to do if the file already exists? I suggest you give them all unique name using GUID.
|
|
|
|
|
will u plz make ur sugesstion some more clear that "give them all unique name using GUID" GUID?
|
|
|
|
|
He means that the Guid type is guaranteed to generate a unique value, so there is no danger of overwriting files. For instance:
string fileDest = Path.Combine(@"c:\Images\Copy", Guid.NewGuid().ToString() + ".gif");
File.Copy(@"c:\Images\MyImage.gif", fileDest);
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
can u suggest a solution for following problem
public static int count = 0;
private void button3_Click_1(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
string s = openFileDialog1.FileName;
textBox6.Text = s;
string st = "Pict" + (count++) + ".jpg";
File.Copy(s.Substring(13, s.Length - 13), "C:\\Inetpub\\wwwroot\\15 WebSite\\images\\" + st);}
i want the image to be saved in local host with the same name as as it was present in hard drive (from where it was browsed)
i have applied ur GUID example but unfortunately its not working, can u apply this in my code?
|
|
|
|
|
Use the File.Exists method to check for the presence of a particular file.
Paul
|
|
|
|
|
You can't keep the filenames the same - you are going to have to change them somehow.
The Guid example would be:
string s = System.IO.Path.GetFileName(openFileDialog1.FileName);
string st = "Pict" + Guid.NewGuid().ToString() + ".jpg";
File.Copy(openDialog1.Filename, Path.Combine(@"c:\inetpub\wwwroot\15 website\images", st));
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
string strQuery = "";
openFileDialog1.ShowDialog();
string s = openFileDialog1.FileName;
textBox6.Text = s;
st2 = s;
string st = "Pict" + Guid.NewGuid().ToString() + ".jpg";
File.Copy(openFileDialog1.FileName, Path.Combine(@"c:\inetpub\wwwroot\15 website\images", st));
strQuery = "INSERT INTO criminal(pic_name) VALUES('"+System.IO.Path.GetFileName(openFileDialog1.FileName)+"')";
SqlCommand com = new SqlCommand(strQuery, conn);
com.ExecuteNonQuery();
PROBLEM:
error comes on this the SQL Query , am i inserting rightly?
or there is some other way
Actually i want to insert only picture name of the picture to be browsed
can u plz suggest any solution
|
|
|
|
|
If you get the solution can you please post it on all the forums your posted this question.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
"I haven't spoken to my wife now for 48 hours. I don't like to interrupt her.
|
|
|
|
|
can anybody tell me what is the vc++ euivalent of the foloowing c# code
n = strXML.IndexOf("\n", n+1);
string Char = strXML.Substring(Pos, 1);
thanks in advance
Vikas da
vikas da
|
|
|
|
|
Depends. Are you using MFC ? the std::string class ? char * buffers to hold strings ?
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi there I have a textbox and want only numeric values to be entered because the value eneterd into the textbox will be written to my database. Thank you
|
|
|
|
|
Handle the KeyPress event and check the pressed key. If it doesn't fit your requirements discard it.
|
|
|
|
|
|
handle the keypress event and write the following code
e.Handled = false;
if (Convert.ToInt16(e.KeyChar) < 48 || Convert.ToInt16(e.KeyChar) > 57)
{
e.Handled = true;
}
|
|
|
|
|
Nouman Bhatti wrote: handle the keypress event and write the following code
e.Handled = false;
if (Convert.ToInt16(e.KeyChar) < 48 || Convert.ToInt16(e.KeyChar) > 57)
{
e.Handled = true;
}
Will not provide a copy paste functionality!
All the best,
Martin
|
|
|
|
|
Thanks for everyone who replied on my question. I cant get it right do you mean :
protected override void OnKeyPress(KeyPressEventArgs e)
{
e.Handled = false;
if (Convert.ToInt16(e.KeyChar) < 48 || Convert.ToInt16(e.KeyChar) > 57)
{
e.Handled = true;
}
}
I have more than one textbox on that form so how do I check only one?
Thanks again.
|
|
|
|
|
Hello,
He meant you should inherit your own NumericTextBox (which has been done about 100 times in the articles)
from Forms.TextBox, and override the OnKeyPress method there.
Or handle the KeyPress event for only the textbox you like to modifie (Like Pete suggested)
yourTextBox.KeyPress+=new KeyPressEventHandler(...);
All the best,
Martin
|
|
|
|