|
i want to thank the all of the pepole that help ech other to improve .
thanks i think i gi ve my answer.
thank u . thank u . thank u.
|
|
|
|
|
Hi
In my application I want to view Windows' Safely Remove Hardware screen from a button instead of clicking the hardware icon on taskbar to see inserted flash disks.
Is there a function to call?
can anyone help me?
|
|
|
|
|
Maybe this article[^] can help?
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
|
Can I get the special xml strings (< & etc) directly instead of being translated?
For example, given the data "RCI>", the code:
xmlReader.ReadStartElement("DATA");
data = xmlReader.ReadString();
xmlReader.ReadEndElement();
Gives: "RCI>". Can I get the raw "RCI>" and if so, how?
Thanks
|
|
|
|
|
use
String.Replace Method
*12Code
|
|
|
|
|
|
That's the one.
Thanks very much.
|
|
|
|
|
I have this code in my project:
<br />
string str;<br />
byte[] enc = new byte[str.length];<br />
enc = Convert.FromBase64String(str);<br />
when i trace it, in the 2nd line the enc is a byte with the length of str but when 3rd line executes the enc length becomes 1 and therefore my data is not valid at the end.
does anybody know what should i do?
Roshanak
|
|
|
|
|
You should know that the base64 encoding is a bit verbose.
I.e. Silly question, silly answer (i.e. please post input values, expected output, actual output if you want better help).
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong.
-- Iain Clarke
[My articles]
|
|
|
|
|
You didn't assign any string to str.
What do you expect enc should be?
*12Code
|
|
|
|
|
The assignment part of second line is not having any use. Your field will be having the return value from FromBase64String method.
Also the length of encrypted string and decrypted string wont be same.
|
|
|
|
|
I'm trying to encrypt sth, and those lines were just a part of my code. I'm sorry for not being clear but i wanted to be brief,
this is the whole code:
<br />
using System;<br />
using System.IO;<br />
using System.Text;<br />
using System.Security.Cryptography;<br />
<br />
namespace Cryptography<br />
{<br />
<br />
public sealed class Cryption<br />
{<br />
private RijndaelManaged Algorithm;<br />
<br />
private string m_key;<br />
private string m_iv;<br />
<br />
private byte[] key;<br />
private byte[] iv;<br />
<br />
<br />
<br />
public Cryption(string key_val, string iv_val)<br />
{<br />
key = new byte[32];<br />
iv = new byte[32];<br />
<br />
int i;<br />
m_key = key_val;<br />
m_iv = iv_val;<br />
<br />
for (i = 0; i < m_key.Length; i++)<br />
{<br />
key[i] = Convert.ToByte(m_key[i]);<br />
}<br />
for (i = 0; i < m_iv.Length; i++)<br />
{<br />
iv[i] = Convert.ToByte(m_iv[i]);<br />
}<br />
<br />
}<br />
<br />
<br />
public string Encrypt(string s)<br />
{<br />
string enc_str;<br />
byte[] enc_byte;<br />
<br />
Algorithm = new RijndaelManaged();<br />
<br />
Algorithm.BlockSize = 256;<br />
Algorithm.KeySize = 256;<br />
Algorithm.Padding = PaddingMode.PKCS7;<br />
<br />
<br />
using (MemoryStream memStream = new MemoryStream())<br />
{<br />
using (ICryptoTransform EncryptorDecryptor = Algorithm.CreateEncryptor(key, iv))<br />
{<br />
using (CryptoStream crStream = new CryptoStream(memStream, EncryptorDecryptor, CryptoStreamMode.Write))<br />
{<br />
UTF8Encoding utf8enc = new UTF8Encoding();<br />
enc_byte = utf8enc.GetBytes(s);<br />
crStream.Write(enc_byte, 0, enc_byte.Length);<br />
crStream.FlushFinalBlock();<br />
}<br />
}<br />
}<br />
<br />
<br />
enc_str = Convert.ToBase64String(enc_byte);<br />
return enc_str;<br />
<br />
}<br />
<br />
<br />
<br />
public string Decrypt(string s)<br />
{<br />
string dec_str;<br />
byte[] decrepted_byte;<br />
<br />
Algorithm = new RijndaelManaged();<br />
<br />
Algorithm.BlockSize = 256;<br />
Algorithm.KeySize = 256;<br />
Algorithm.Padding = PaddingMode.PKCS7;<br />
<br />
<br />
byte[] dec_byte = new byte[s.Length];<br />
dec_byte = Convert.FromBase64String(s);<br />
decrepted_byte = new byte[dec_byte.Length];<br />
<br />
using (MemoryStream memStream = new MemoryStream(dec_byte))<br />
{<br />
using (ICryptoTransform EncryptorDecryptor = Algorithm.CreateDecryptor(key, iv))<br />
{<br />
using (CryptoStream crStream = new CryptoStream(memStream, EncryptorDecryptor, CryptoStreamMode.Read))<br />
{<br />
crStream.Read(decrepted_byte, 0, decrepted_byte.Length);<br />
}<br />
}<br />
}<br />
<br />
UTF8Encoding utf8enc = new UTF8Encoding();<br />
dec_str = utf8enc.GetString(decrepted_byte);<br />
return dec_str;<br />
<br />
}<br />
<br />
}<br />
}<br />
so, you see none of the answers could help me!
|
|
|
|
|
Roshanakak wrote: none of the answers could help me!
because you gave fictitious code to start with.
|
|
|
|
|
|
How m i going to unit testing this kind of function?
plz help.
private void saverecord()
{
OleDbConnection savecon = new OleDbConnection(constring);
OleDbCommand savecom = new OleDbCommand("insert into Employee_Details values (?,?,?)", savecon);
OleDbParameter param;
param = savecom.Parameters.Add("@empcode", OleDbType.VarChar, 10);
param.Value = txtcode.Text;
param = savecom.Parameters.Add("@empname", OleDbType.VarChar, 25);
param.Value = txtname.Text;
param = savecom.Parameters.Add("@empjoin", OleDbType.Date);
param.Value = DateTime.Now.ToShortDateString();
savecon.Open();
int rows = savecom.ExecuteNonQuery();
MessageBox.Show(rows.ToString() + "rows affected");
btnref.PerformClick();
savecon.Close();
}
[TestMethod()]
public void saverecordTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
target.saverecord();
//Assert.Inconclusive("A method that does not return a value cannot be verified.");
}
|
|
|
|
|
Best way would be to seperate your GUI (form) from your dataaccess. This will give you the opportunity to test GUI and data-access seperately.
For GUI testing use mocks to simulate the data-access. Testing the data-access is simple, just call your saveRecord-Method and try to read the record afterwards (don't forget to cleanup afterwards).
Regards
Sebastian
|
|
|
|
|
okay..another question,is it necessary to use assert? when shuold we use assert and when not?
for example,how to insert the assert to verify the result?
[TestMethod()]
public void saverecordTest()
{
Form1_Accessor target = new Form1_Accessor(); // TODO: Initialize to an appropriate value
target.txtcode.Text = "19095";
target.txtname.Text = "453427";
target.txtaddress.Text = "s34235";
target.saverecord();
}
|
|
|
|
|
Well using assert is necessary. What you want to test is whether your saveRecord()-method works correct. What if the method has a bug and txtcode and txtname are interchanged. You won't get an exception, so you will need an Assert. (Whenever you don't get an exception, use Assert !)
After saving the record you have to read the values which were stored. Use the Assert-statement to check if the values are stored correctly.
...
target.saverecord();
Assert.IsTrue(...Equals("19095"));
As I said before, I suggest to refactor your code so that you have a datalayer and a GUI. This will make unit testing easier. Also take a quick look into the NUnit-Quickstart documentation. They provide a well-known example.
Regards
Sebastian
|
|
|
|
|
Hello,can someone instruct me how to capture network video stream.I want to capture video stream from msn messenger,until now I have found several frameworks,but didn't find how to capture video from msn over network to my HDD.Thx
Servia Nostrum Regnum
|
|
|
|
|
Anyone?
Servia Nostrum Regnum
|
|
|
|
|
Hello Friends,
I need your help regarding the socket programming . Let say i am in the server system . Client has send a xml file using TCP to a specific port . My problem when i read data using NetworkStream then then it has been stopped there not able to find it out where is the problem , even it does not through any error .
But when i send and receive data to the same system ( mean to say the server and client is same ) then its working fine . I am able to receive data . But when server and client is different then the problem occurs . I am puuting the sample code . Please look into the code and help me if you people have any idea .
TcpClient c = new TcpClient("Test", 1027);
NetworkStream ns = c.GetStream(); // get stream
byte[] buf = new byte[8024]; // create byte array to receive data
ns.Read(buf, 0, 8020); // read data from stream into byte array
// read data from stream into byte array
string st = System.Text.Encoding.ASCII.GetString(buf); // convert byte array to string
// create a writer and open the file
TextWriter tw = new StreamWriter("D:\\test.txt");
// write a line of text to the file
tw.WriteLine(st.ToString());
// close the stream
tw.Close();
c.Close();
Console.WriteLine(st);
|
|
|
|
|
i want to save gridview values in database. here some fields are fetched from one table that fields are empname empid empphoneno and remaining fields are time and attendence. i used radio button list for attendence column. the list is present, obsent and leave. the selected value and remaining fields are save in another table plz give me solution i am using sql 2005 and c#
|
|
|
|
|
anybody give me code for this
|
|
|
|
|
protected void btnSave_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
foreach (GridViewRow gvr in gvWorkGroup.Rows)
{
new StockInformation_FK().SaveItemes(txtItemId.Text, ddlCatagoryName.SelectedValue, ddlSupplierName.SelectedValue, ddlBrand.SelectedValue, txtItemName.Text, txtPartNo.Text, txtSerialNo.Text, ddlStatus.SelectedValue, txtPrice.Text, dtPurchase.Text, dtWarranty.Text, txtInvoiceNo.Text, txtRemarks.Text, "");
}
ShowSuccesMessage(LoadSucessMsg());
ClearAll();
LoadGrid();
}
catch (Exception ex)
{
throw ex;
}
}
}
modified on Thursday, September 15, 2011 5:43 AM
|
|
|
|