|
Colin Angus Mackay wrote: wreck a nice beach
ROFL
var question = (_2b || !(_2b));
|
|
|
|
|
Take a look Here[^].
Those tools are not free, though.
|
|
|
|
|
Hello there,
I am working on a small Windows form, where I've to implelent the LinkLabel control to link my form with www.microsoft.com. Below is the code:
private void linkLabel1_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(www.microsoft.com);
}
But when I debug the code, I get an error which is like this "The name www does not exist in the current context".
Can anyone please tell me, whats the correct code for the LinkLabel event handler, such that my form connects to microsoft.com.
Your help would be appreciated! Thanx.
|
|
|
|
|
Put the URL in quotes.
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)
|
|
|
|
|
Thanx for helping me out. You guys see, I was doing such a silly mistake! But a lot of thanx to u both. Hope to recieve more help from u folks in future also. Take care....
|
|
|
|
|
Just as a tip, you could make that event slightly more situation-generic by starting e.Link, instead of a hardcoded string. Then you simply have to set the LinkLabel's Links property accordingly, and you don't have to dip into code in order to change the link destination
|
|
|
|
|
Hi there guys,
where should I place e.Link as suggested by Computafreak?
I am coding the the LinkLabel Event Handler with:
{
System.Diagnostics.Process.Start("www.microsoft.com");
}
Where should I add e.Link to make it more situation-generic?
|
|
|
|
|
You'd need to do something like this (assuming you just want the whole text to be one link - you can have a link for as many characters as there are in the Text!).
linkLabel1.Text = "Go to Microsoft's web site";
linkLabel1.Links[0].LinkData = "http://www.microsoft.com";
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (e.Link.LinkData is string)
{
string url = (string)e.Link.LinkData;
System.Diagnostics.Process.Start(url);
}
}
[Edit] Just had a quick play and the above works fine, but you could maybe improve it with something like this:
string keyText = "Microsoft";
linkLabel1.Text = string.Format("Go to {0}'s web site", keyText);
linkLabel1.Links[0].Start = linkLabel1.Text.IndexOf(keyText);
linkLabel1.Links[0].Length = keyText.Length;
linkLabel1.Links[0].LinkData = string.Format("http://www.{0}.com", keyText); [/Edit]
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)
modified on Wednesday, April 1, 2009 7:36 AM
|
|
|
|
|
Hi, I've entered this code in the LinkLabel_LinkClicked Event Handler, as suggested by you (Dave):
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (e.Link.LinkData is string)
{
string url = (string)e.Link.LinkData; System.Diagnostics.Process.Start("www.microsoft.com");
}
}
//Please see whether I have enetered the correct code!
But tell me where do I enter this code, in which event:
linkLabel1.Text = "Go to Microsoft's web site";linkLabel1.Links[0].LinkData = "http://www.microsoft.com";
|
|
|
|
|
I think you're getting a bit mixed up.
Work it out from the full sample below - I've just created a new project, and dragged a LinkLabel onto Form1.
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
linkLabel1.LinkClicked += new LinkLabelLinkClickedEventHandler(linkLabel1_LinkClicked);
string keyText = "Microsoft";
linkLabel1.Text = string.Format("Go to {0}'s web site", keyText);
linkLabel1.Links[0].Start = linkLabel1.Text.IndexOf(keyText);
linkLabel1.Links[0].Length = keyText.Length;
linkLabel1.Links[0].LinkData = string.Format("http://www.{0}.com", keyText);
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
if (e.Link.LinkData is string)
{
string url = (string)e.Link.LinkData;
System.Diagnostics.Process.Start(url);
}
}
}
}
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)
|
|
|
|
|
Thanx Davey!
U did so much for me! U r great! Actually, I am not that expert like u guys. I am only a begineer, trying to figure myself out in the IT industry. Can u give me your Email address such that I can send u a greetings of compliment. Hope to hear from u soon in the forum.
Take care Genius!
Rajdeep
|
|
|
|
|
You're welcome. That's why we come here - to help, and be helped when needed.
We were all beginners at one time so don't worry about that, and welcome to CodeProject.
(You can email me through the link that's at the bottom of each post.)
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)
|
|
|
|
|
No problem
I normally use my own version of the link label which I've just added a URL property to and overridden the OnClick so it starts the process automatically with no coding needed.
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Forms;
namespace WinForms.Controls
{
public class URLLabel : LinkLabel
{
public URLLabel()
{
URL = "about:blank";
}
[DefaultValue("about:blank"),
Description("The URL that will launched in the default browser when the label is clicked.")]
public string URL
{
get;
set;
}
protected override void OnClick(EventArgs e)
{
try
{
Process.Start(URL);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
finally
{
base.OnClick(e);
}
}
}
}
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)
|
|
|
|
|
I've not tested this, but have you tried something like System.Diagnostics.Process.Start("HTTP://www.microsoft.com"); ??
oooo, the Jedi's will feel this one....
|
|
|
|
|
Hi Everyone.
I'm pretty new to C#, and I'm having a bit of a problem. I have an application which will be saving passwords to an xml document, so I want to encrypt them. I have created some simple code which manages to encrypt the information but complains when I try to decrypt it with “Padding is invalid and cannot be removed”. I have tried different padding modes including PaddingMode.None with no luck.
I’m sure I'm missing something simple... Please can somebody help me???
Thanks
Code
class Program
{
static void Main(string[] args)
{
string Orig = "Paul Unsworth";
string Key = "as^le)ds~{3sjlk3*$ake^ia29?jf%a!";
string IV = "ad|k#f(*&lk$df()";
string Encrypted = Encrypt(Orig, Key, IV);
string Decrypted = Decrypt(Encrypted, Key, IV);
Console.WriteLine("Original Text:\r\n {0}", Orig);
Console.WriteLine("Encrypted Text:\r\n {0}", Encrypted);
Console.WriteLine("Decrypted Text:\r\n {0}", Decrypted);
Console.ReadLine();
}
static string Encrypt(string val, string key, string iv)
{
byte[] bVal = toBytes(val);
byte[] bKey = toBytes(key);
byte[] bIV = toBytes(iv);
MemoryStream ms = new MemoryStream();
Rijndael r = Rijndael.Create();
r.Key = bKey;
r.IV = bIV;
r.Padding = PaddingMode.PKCS7;
CryptoStream cs = new CryptoStream(ms, r.CreateEncryptor(), CryptoStreamMode.Write);
cs.Write(bVal, 0, bVal.Length);
cs.Close();
string result = toString(ms.ToArray());
ms.Close();
return result;
}
static string Decrypt(string val, string key, string iv)
{
byte[] bVal = toBytes(val);
byte[] bKey = toBytes(key);
byte[] bIV = toBytes(iv);
MemoryStream ms = new MemoryStream();
Rijndael r = Rijndael.Create();
r.Key = bKey;
r.IV = bIV;
r.Padding = PaddingMode.PKCS7;
CryptoStream cs = new CryptoStream(ms, r.CreateDecryptor(), CryptoStreamMode.Write);
cs.Write(bVal, 0, bVal.Length);
cs.Close();
string result = toString(ms.ToArray());
ms.Close();
return result;
}
static byte[] toBytes(string str)
{
ASCIIEncoding a = new ASCIIEncoding();
return a.GetBytes(str);
}
static string toString(byte[] b)
{
ASCIIEncoding a = new ASCIIEncoding();
return a.GetString(b);
}
}
oooo, the Jedi's will feel this one....
|
|
|
|
|
Hey Monkey,
Your problem seems a bit tough to me... why not consult some expert programmer and if possible shorten the code. Good programmers often find it harassing reading such long codes.
Happy Programming.....
|
|
|
|
|
Hmm forums say that this might be a problem if everything is not read to the end. Call cs.Flush() before you close the CryptoStream.
If this doesn't work, I would think about using an hash-algorithm because you don't need to decrypt the password ever again. Just encrypt the user input and check if this equals the stored hash before.
Regards
Sebastian
|
|
|
|
|
Thanks for your reply Sebastian.
I've tried cs.Flush() and unfortunatly it did not work.
The pain in the backside is I need to be able to decrypt the password, as it is for SQL Server Authentication. The app is to run/create a load of old long standing reports automatically, and for this, the User Name and Password need to be passed to SQL Server. (We have people unwilling to move away from excel workbooks to better reporting methods in this company )
Thanks for you help...
oooo, the Jedi's will feel this one....
|
|
|
|
|
Hi, I had a look and can't see where this is going wrong. I have the below code though that I know works and which I use to encrypt passwords to and from the Database.
public static string Encrypt(string plainText,
string passPhrase,
string saltValue,
string hashAlgorithm,
int passwordIterations,
string initVector,
int keySize)
{
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] salValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText);
PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase,
salValueBytes, hashAlgorithm, passwordIterations);
byte[] keyBytes = password.GetBytes(keySize / 8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes,
initVectorBytes);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor,
CryptoStreamMode.Write);
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
cryptoStream.FlushFinalBlock();
byte[] cipherTextBytes = memoryStream.ToArray();
memoryStream.Close();
cryptoStream.Close();
string cipherText = Convert.ToBase64String(cipherTextBytes);
return cipherText;
}
public static string Decrypt(string cipherText,
string passPhrase,
string saltValue,
string hashAlgorithm,
int passwordIterations,
string initVector,
int keySize)
{
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue);
byte[] cipherTextBytes = Convert.FromBase64String(cipherText);
PasswordDeriveBytes password = new PasswordDeriveBytes(
passPhrase,
saltValueBytes,
hashAlgorithm,
passwordIterations);
byte[] keyBytes = password.GetBytes(keySize / 8);
RijndaelManaged symmetricKey = new RijndaelManaged();
symmetricKey.Mode = CipherMode.CBC;
ICryptoTransform decryptor = symmetricKey.CreateDecryptor(
keyBytes,
initVectorBytes);
MemoryStream memoryStream = new MemoryStream(cipherTextBytes);
CryptoStream cryptoStream = new CryptoStream(memoryStream,
decryptor,
CryptoStreamMode.Read);
byte[] plainTextBytes = new byte[cipherTextBytes.Length];
int decryptedByteCount = cryptoStream.Read(plainTextBytes,
0,
plainTextBytes.Length);
memoryStream.Close();
cryptoStream.Close();
string plainText = Encoding.UTF8.GetString(plainTextBytes,
0,
decryptedByteCount);
return plainText;
}
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
I have been having a look at the below and I can't figure this out as well. However, I have the below code that works which I use to encrypt passwords to and from the DB.
//Encrypt Value formatted as a base64-encoded string. public static string Encrypt(string plainText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize) { //Covert strings into byte arrays. byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector); byte[] salValueBytes = Encoding.ASCII.GetBytes(saltValue); //Convert our plaintext password to a byte array. byte[] plainTextBytes = Encoding.UTF8.GetBytes(plainText); //Create a password from which the value will be derived PasswordDeriveBytes password = new PasswordDeriveBytes(passPhrase, salValueBytes, hashAlgorithm, passwordIterations); //Use the password to generate psuedo-random bytes for encryption key. //Specify the size of the key in bytes (intead of bits). byte[] keyBytes = password.GetBytes(keySize / 8); //Create uninitialized Rijndael encryption object. RijndaelManaged symmetricKey = new RijndaelManaged(); //Set encryption mode to Cipher Block Chaining(CBC). symmetricKey.Mode = CipherMode.CBC; //Generate encryptor from the existing key bytes and initialization vector. ICryptoTransform encryptor = symmetricKey.CreateEncryptor(keyBytes, initVectorBytes); //Define memorystream to hold encrypted data. MemoryStream memoryStream = new MemoryStream(); //Define Cryptographic stream. (Always use write mode) CryptoStream cryptoStream = new CryptoStream(memoryStream, encryptor, CryptoStreamMode.Write); //Start Encrypting cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length); //Finish encrypting cryptoStream.FlushFinalBlock(); //Convert encrypted stream to a byte array byte[] cipherTextBytes = memoryStream.ToArray(); //Close both streams memoryStream.Close(); cryptoStream.Close(); //Convert to encrypted into base64-encoding string string cipherText = Convert.ToBase64String(cipherTextBytes); //return encrypted string return cipherText; } //Now for the Decyption. public static string Decrypt(string cipherText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize) { byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector); byte[] saltValueBytes = Encoding.ASCII.GetBytes(saltValue); byte[] cipherTextBytes = Convert.FromBase64String(cipherText); PasswordDeriveBytes password = new PasswordDeriveBytes( passPhrase, saltValueBytes, hashAlgorithm, passwordIterations); byte[] keyBytes = password.GetBytes(keySize / 8); RijndaelManaged symmetricKey = new RijndaelManaged(); symmetricKey.Mode = CipherMode.CBC; ICryptoTransform decryptor = symmetricKey.CreateDecryptor( keyBytes, initVectorBytes); MemoryStream memoryStream = new MemoryStream(cipherTextBytes); CryptoStream cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read); byte[] plainTextBytes = new byte[cipherTextBytes.Length]; int decryptedByteCount = cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length); memoryStream.Close(); cryptoStream.Close(); string plainText = Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount); return plainText; }
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Thats great. Thanks guys. I'll give your code a try...
oooo, the Jedi's will feel this one....
|
|
|
|
|
how can i get all files handled by a specific process without using WMI
in c#?
|
|
|
|
|
Do you mean this one?
foreach(ProcessModule pm in Process.GetCurrentProcess().Modules)
{
Console.WriteLine(pm.FileName);
}
|
|
|
|
|
No,I didn't mean modules of a process.
What i need get non executable files associated to a process like .doc , .pdf
|
|
|
|
|
|