|
The problem is to find a good pattern: how to describe what's url and what isn't. One problem is that when you find an url inside a text, when does it stop? To the next space, punctuation char etc.
I Googled a bit and found several discussions about indentifying url. Have a look: http://www.google.com/search?hl=en&q=regex+find+url&meta=[^]
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
That was also what I was thinking "when does it stop? To the nex..." Thanks for the link I don't know what it is with me and Google, others always seem to find links that I cannot. Haha
j.t.
|
|
|
|
|
Hi
As you know System.Windows.Forms.SendKeys.Send() method has some special codes to specify keys. I want to send Left or Right shift key, but the Send method does not support it. (Send("+"))
How can I send Left/Right shift key in C#?
Any help is appreciated.
|
|
|
|
|
how can i install a converted calendar as an add-on for office 2007?
|
|
|
|
|
Hi,
Is it possible to retrieve image directly from database and displaying it in image control? If so then guide me...
modified on Saturday, November 15, 2008 3:46 AM
|
|
|
|
|
Your question is too large to answer in depth. If your problem is the datatype and the data is stored in a varbinary (or image) column, when you fetch it, you use byte array for the parameter type.
First build the basic communication between client and db. Then add varbinary column to your select statement. If you have specific problems, you should post the code that's causing the problem. This way it would be possible to answer the question.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
of course my horse
do you want to load it to crystal reports or a form control?
check here for "load image from database", you will get many articles.
i got it from there.
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
I plan to distribute an application in the near future. One thing I have not been able to find thus far concerns adding code that requires a user to enter a registration key to fully enable an application. I would appreciate any guidance in this regard.
Thank you in advance.
|
|
|
|
|
 An idea, I implemented a while ago:
Create a license-file (with the required information), create a hash over the file, sign this hash with a e.g. RSA implementation, include the public key in your app.
To generate a license, the user submits the license information to you, you create the license file and sign it with your private key.
Your app searches for the license file, reads and verifies it, if the signature is ok.
Hendrik
This VB.NET code might help you ...
Option Explicit On
Option Strict On
Imports System.IO
Imports System.Text
Imports System.Security.Cryptography
Imports Microsoft.VisualBasic
Public Class clsLicenseEngine
Public Structure TYPE_LicenseFile
' License Information
Private m_LicenseName As String
Private m_LicenseCompany As String
Private m_LicenseFlags As String
Private m_LicenseNumber As String
Private m_Hash() As Byte
Private m_Signature() As Byte
Public Property LicenseName() As String
Get
Return m_LicenseName
End Get
Set(ByVal value As String)
m_LicenseName = value
End Set
End Property
Public Property LicenseCompany() As String
Get
Return m_LicenseCompany
End Get
Set(ByVal value As String)
m_LicenseCompany = value
End Set
End Property
Public Property LicenseFlags() As String
Get
Return m_LicenseFlags
End Get
Set(ByVal value As String)
m_LicenseFlags = value
End Set
End Property
Public Property LicenseNumber() As String
Get
Return m_LicenseNumber
End Get
Set(ByVal value As String)
m_LicenseNumber = value
End Set
End Property
Public ReadOnly Property Hash() As Byte()
Get
Return m_Hash
End Get
End Property
Public Function LicenseSplitFlags() As String()
Dim retVal() As String
Dim splitter() As Char = {Chr(Asc("~"))}
retVal = m_LicenseFlags.Split(splitter, StringSplitOptions.RemoveEmptyEntries)
Return retVal
End Function
Private Function HashCalculate() As Byte()
Dim SHA1 As New SHA1Managed
Dim utf8 As New UTF8Encoding
Dim retVal() As Byte
Dim LicenseBuffer() As Byte = utf8.GetBytes(m_LicenseName + vbCrLf + m_LicenseCompany + vbCrLf + m_LicenseFlags + vbCrLf + m_LicenseNumber)
retVal = SHA1.ComputeHash(LicenseBuffer)
Return retVal
End Function
Private Sub HashSet()
m_Hash = HashCalculate()
End Sub
Public Function AdminSignLicense(ByVal PrivateKey As TYPE_Key) As Boolean
If PrivateKey.PrivateKeySet = False Then
Return False
End If
HashSet()
Dim m_rsa As New RSACryptoServiceProvider
m_rsa.ImportParameters(PrivateKey.PrivateKey)
Dim Sign As New RSAPKCS1SignatureFormatter(m_rsa)
Sign.SetHashAlgorithm("SHA1")
m_Signature = Sign.CreateSignature(m_Hash)
Return True
End Function
Public Function CheckSignature(ByVal PublicKey As TYPE_Key) As Boolean
Dim m_rsa As New RSACryptoServiceProvider
m_rsa.ImportParameters(PublicKey.PublicKey)
Dim sign As New RSAPKCS1SignatureDeformatter(m_rsa)
sign.SetHashAlgorithm("SHA1")
Return sign.VerifySignature(m_Hash, m_Signature)
End Function
Public Function AdminWriteLicenseFile(ByVal FileName As String) As Boolean
Dim fs As Stream
Dim utf8 As New UTF8Encoding
Dim lines() As String = {m_LicenseName, m_LicenseCompany, m_LicenseFlags, m_LicenseNumber}
Dim buffer() As Byte
ReDim Preserve lines(lines.Length + 1)
lines(lines.Length - 2) = ArrayToHexString(m_Hash)
lines(lines.Length - 1) = ArrayToHexString(m_Signature)
Try
fs = New FileStream(FileName, FileMode.Create)
For Each line As String In lines
buffer = utf8.GetBytes(line + vbLf)
fs.Write(buffer, 0, buffer.Length)
Next
fs.Flush()
fs.Close()
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function ReadLicenseFile(ByVal FileName As String) As Boolean
Dim fs As Stream
Dim utf8 As New UTF8Encoding
Dim lines() As String
Dim LongLine As String
Dim lf() As Char = {CType(vbLf, Char)}
Try
fs = New FileStream(FileName, FileMode.Open)
Dim buffer(CType(fs.Length - 1, Integer)) As Byte
fs.Read(buffer, 0, CType(fs.Length, Integer))
LongLine = utf8.GetString(buffer)
lines = LongLine.Split(lf, StringSplitOptions.None)
Catch ex As Exception
Return False
End Try
m_LicenseName = lines(0)
m_LicenseCompany = lines(1)
m_LicenseFlags = lines(2)
m_LicenseNumber = lines(3)
m_Hash = HexStringToArray(lines(4))
HashSet()
m_Signature = HexStringToArray(lines(5))
Return True
End Function
Private Function ArrayToHexString(ByVal data() As Byte) As String
Dim retVal As String = ""
Dim i As Integer
For i = 0 To data.Length - 1
If Hex(data(i)).Length = 1 Then
retVal = retVal + "0"
End If
retVal = retVal + Hex(data(i))
Next
Return retVal
End Function
Private Function HexStringToArray(ByVal HexString As String) As Byte()
Dim retVal(CType(((HexString.Length) / 2) - 1, Integer)) As Byte
Dim i As Integer
For i = 1 To HexString.Length Step 2
retVal(CType((i - 1) / 2, Integer)) = CType(Val("&H" + Mid(HexString, i, 2)), Byte)
Next
Return retVal
End Function
End Structure
Public Structure TYPE_Key
Private m_PrivateKey As RSAParameters
Private m_PublicKey As RSAParameters
Private m_PrivateKeySet As Boolean
Public Property PrivateKey() As RSAParameters
Get
Return m_PrivateKey
End Get
Set(ByVal value As RSAParameters)
m_PrivateKey = value
m_PrivateKeySet = True
SetPublicKey()
End Set
End Property
Public Property PublicKey() As RSAParameters
Get
Return m_PublicKey
End Get
Set(ByVal value As RSAParameters)
m_PublicKey = value
m_PrivateKeySet = False
End Set
End Property
Public ReadOnly Property PrivateKeySet() As Boolean
Get
Return m_PrivateKeySet
End Get
End Property
Public Sub Clear()
m_PrivateKey = Nothing
m_PublicKey = Nothing
m_PrivateKeySet = False
End Sub
Private Sub SetPublicKey()
Dim m_rsa As New RSACryptoServiceProvider
m_rsa.ImportParameters(m_PrivateKey)
m_PublicKey = m_rsa.ExportParameters(False)
End Sub
Public Function WritePrivateKey(ByVal FileName As String) As Boolean
If m_PrivateKeySet = False Then
Return False
End If
Dim fs As Stream
Dim m_rsa As New RSACryptoServiceProvider
m_rsa.ImportParameters(m_PrivateKey)
Dim m_privKey() As Byte = m_rsa.ExportCspBlob(True)
Try
fs = New FileStream(FileName, FileMode.Create)
fs.Write(m_privKey, 0, m_privKey.Length)
fs.Flush()
fs.Close()
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function WritePublicKeyVB(ByVal FileName As String) As Boolean
Dim utf8 As New UTF8Encoding
Dim tmp As String
Dim buffer() As Byte
Dim fs As Stream
Dim m_rsa As New RSACryptoServiceProvider
m_rsa.ImportParameters(m_PublicKey)
Dim m_PubKey() As Byte = m_rsa.ExportCspBlob(False)
Try
fs = New FileStream(FileName, FileMode.Create)
tmp = "Public LicenseEnginePubKey() As Byte = { _" + vbCrLf
buffer = utf8.GetBytes(tmp)
fs.Write(buffer, 0, buffer.Length)
Dim i As Integer
For i = 0 To m_PubKey.Length - 1
tmp = "&H" + Hex(m_PubKey(i))
If i < m_PubKey.Length - 1 Then
tmp = tmp + ", "
If (i Mod 20 = 0) And (i > 0) Then
tmp = tmp + "_" + vbCrLf
End If
Else
tmp = tmp + " _ " + vbCrLf + "}"
End If
buffer = utf8.GetBytes(tmp)
fs.Write(buffer, 0, buffer.Length)
Next
fs.Flush()
fs.Close()
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function WritePublicKey(ByVal FileName As String) As Boolean
Dim fs As Stream
Dim m_rsa As New RSACryptoServiceProvider
m_rsa.ImportParameters(m_PublicKey)
Dim m_pubKey() As Byte = m_rsa.ExportCspBlob(False)
Try
fs = New FileStream(FileName, FileMode.Create)
fs.Write(m_pubKey, 0, m_pubKey.Length)
fs.Flush()
fs.Close()
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Sub SetKeyBinary(ByVal key() As Byte)
Dim m_rsa As New RSACryptoServiceProvider
m_rsa.ImportCspBlob(key)
Try
PrivateKey = m_rsa.ExportParameters(True)
Catch ex As Exception
PublicKey = m_rsa.ExportParameters(False)
End Try
End Sub
Public Function ReadKey(ByVal FileName As String) As Boolean
Dim fs As Stream
Dim m_rsa As New RSACryptoServiceProvider
Try
fs = New FileStream(FileName, FileMode.Open)
Dim keylenght As Integer = CType(fs.Length, Integer)
Dim key(keylenght - 1) As Byte
fs.Read(key, 0, keylenght)
fs.Close()
Clear()
m_rsa.ImportCspBlob(key)
Catch ex As Exception
Return False
End Try
Try
PrivateKey = m_rsa.ExportParameters(True)
Catch ex As Exception
PublicKey = m_rsa.ExportParameters(False)
End Try
Return True
End Function
Public Sub GenerateNewKey()
Dim m_rsa As New RSACryptoServiceProvider
PrivateKey = m_rsa.ExportParameters(True)
End Sub
End Structure
End Class
|
|
|
|
|
I have written a singleton application as follows:
public static class SingletonApp
{
static Mutex m_Mutex;
public static void Run( Form mainForm )
{
bool first = IsFirstInstance( );
if( first )
{
Application.ApplicationExit += OnExit;
Application.Run( mainForm );
}
else
{
}
}
static bool IsFirstInstance( )
{
Assembly assembly = Assembly.GetEntryAssembly( );
string name = assembly.FullName;
m_Mutex = new Mutex( false , name );
bool owned = false;
owned = m_Mutex.WaitOne( TimeSpan.FromSeconds(0) , false );
return owned;
}
static void OnExit( object sender , EventArgs args )
{
m_Mutex.ReleaseMutex( );
m_Mutex.Close( );
}
}
When this application is running(minimized mode),I hope to open its main window(Form mainForm above in Run method).In order to implement this function(similar to Microsoft Outlook),how should I add other code?
Thank you very much!
|
|
|
|
|
|
You could use for example Process.GetProcessesByName[^] method to find the existing instance and then invoke a method on that instance using reflection. The method could simply set the main forms window state to normal.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Mika,Thank you very much!
I have added a line in that else statement above as follows:
Process[] singleInstance = Process.GetProcessesByName( "SingletonApp" );
But in turn ,how shall I write using reflection ?
May you help to write that code followed?
I am looking forward to your reply again!
Thank you very much again!
|
|
|
|
|
I believe that the article Giorgi posted is excellent. Use that and explore the communication. The only thing I would consider in that article is that perhaps IpcChannel could be used instead of TcpChannel.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
 There is a solution to this problem using some unmanaged code as follows:
public static class SingletonApp
{
[DllImport( "user32.dll" )]
static extern bool SetForegroundWindow( IntPtr hWnd );
[DllImport( "user32.dll" )]
static extern bool ShowWindowAsync( IntPtr hWnd , int nCmdShow );
[DllImport( "user32.dll" )]
static extern bool IsIconic( IntPtr hWnd );
const int SW_RESTORE = 9;
static Mutex m_Mutex;
public static void Run( Form mainForm )
{
bool first = IsFirstInstance( );
if( first )
{
Application.ApplicationExit += OnExit;
Application.Run( mainForm );
}
else
{
Process current = Process.GetCurrentProcess( );
Process[ ] procs = Process.GetProcessesByName( current.ProcessName );
IntPtr mainWindowHandle = procs[0].MainWindowHandle;
if( IsIconic( mainWindowHandle ) )
{
ShowWindowAsync( mainWindowHandle , SW_RESTORE );
}
SetForegroundWindow( mainWindowHandle );
}
}
static bool IsFirstInstance( )
{
Assembly assembly = Assembly.GetEntryAssembly( );
string name = assembly.FullName;
m_Mutex = new Mutex( false , name );
bool owned = false;
owned = m_Mutex.WaitOne( TimeSpan.FromSeconds(0) , false );
return owned;
}
static void OnExit( object sender , EventArgs args )
{
m_Mutex.ReleaseMutex( );
m_Mutex.Close( );
}
}
But,there seems to be timing issues yet!
It is sometimes required to double-click executable twice in order to set
that existing instance into the foreground,which cannot be a lot understood!
I strongly expect someone to supply a better solution that is completely managed code!
Thank you very much!
|
|
|
|
|
Hi all,
i'm having problem in custom paging using web application..there is an error saying "Input string was not in a correct format."
Here is my coding..
protected void NavigationLink_Click ( Object sender, CommandEventArgs e )
{
switch ( e.CommandName )
{
case "First":
_currentPageNumber = 1;
break;
case "Last":
_currentPageNumber = Int32.Parse(TotalPages.Text);
break;
case "Next":
_currentPageNumber = Int32.Parse(CurrentPage.Text) + 1;
break;
case "Prev":
_currentPageNumber = Int32.Parse(CurrentPage.Text) - 1;
break;
}
BindData();
}
public void BindData()
{
OdbcConnection myconn;
myconn= new OdbcConnection ("DSN=myodbc2;SERVER=localhost;DATABASE=misdb;UID=root;PORT=3306");
OdbcCommand cmd2 = new OdbcCommand("Select * from registration", myconn);
cmd2.CommandType=CommandType.StoredProcedure;
cmd2.Parameters.Add(new OdbcParameter ("@CurrentPage",OdbcType.Numeric,10)).Value=_currentPageNumber;
cmd2.Parameters.Add(new OdbcParameter("@PageSize",OdbcType.Numeric,10)).Value=DataGrid.PageSize;
cmd2.Parameters.Add(new OdbcParameter("@TotalRecords",OdbcType.Numeric,10)).Direction =ParameterDirection.Output;
try
{
myconn.Open();
DataGrid.DataSource=cmd2.ExecuteReader();
DataGrid.DataBind();
}
finally
{
myconn.Close();
}
CurrentPage.Text=_currentPageNumber.ToString();
Double _totalPages = 1;
if ( !Page.IsPostBack )
{
Int32 _totalRecords = (Int32) cmd2.Parameters["@TotalRecords"].Value;
totalPages = _totalRecords / DataGrid.PageSize;
TotalPages.Text =(System.Math.Ceiling(_totalPages)).ToString();
}
else
{
_totalPages = Double.Parse(TotalPages.Text);
}
if ( _currentPageNumber == 1 )
{
PreviousPage.Enabled = false;
if ( _totalPages > 1 )
{
NextPage.Enabled = true;
}
else
{
NextPage.Enabled = false;
}
}
else
{
PreviousPage.Enabled = true;
if ( _currentPageNumber == _totalPages )
{
NextPage.Enabled = false;
}
else
{
NextPage.Enabled = true;
}
}
}
%#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG
|
|
|
|
|
Entering something in the CurrentPage field would cause that to happen.
To avoid that, use the int.TryParse method to parse the value so that you can easily detect any illegal input.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
hI,
I cant c TryParse method in program.Got any other solution for this problem..?
%#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG
|
|
|
|
|
Of course you can't see any TryParse in the program. I said that you should use TryParse in the program.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
ok thank you.
%#&kmpYrlHSGYG5@#($_+!@!(*JASnjshdk,cm_0ashjhdbn@#$!48mkhfbchsh))^%#W%&@YW7wsdfjw789';'][]\`~JKJQ4$!@#~)-HSKS^&*1)JK12@#@$~!1`DFGkqp][]\]?Zas;EWRG%!@~)(^&BVAG
|
|
|
|
|
Hi,
i have a xml file embedded in my project resources. I can read it but i can´t save changes on it, check code bellow
DataSet ds = new DataSet();
ds.ReadXml(Class_Helper.ResourceXml_login, XmlReadMode.ReadSchema);
DataGridView_Administrator.DataSource = ds.Tables[0];
DataRow DataRow_user = ds.Tables[0].NewRow();
DataRow_user["id"] = 10;
DataRow_user["f_name"] = ToolStripTextBox_FName.Text;
DataRow_user["l_name"] = ToolStripTextBox_LName.Text;
DataRow_user["username"] = ToolStripTextBox_Username.Text;
DataRow_user["password"] = ToolStripTextBox_Password.Text;
DataRow_user["role"] = ToolStripComboBox_Role.Text;
ds.Tables[0].Rows.Add(DataRow_user);
ds.WriteXml(Class_Helper.ResourceXml_login,XmlWriteMode.WriteSchema);
DataGridView_Administrator.DataSource = ds.Tables[0];
i can save changes if i use the path way you know?! but i want this way and i really dont know where the codes goes wrong
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Of course you can't do this. First of all, resources are Read Only. Second, in order to save those changes, the .EXE file cannot be running because a running .EXE's file is locked by the system. So, in order to update the resource, you have to NOT be running the code.
nelsonpaixao wrote: but i want this way and i really dont know where the codes goes wrong
It's not the code that's going wrong, but your entire concept. You simply cannot do what you want.
|
|
|
|
|
thanks, i didn´t know that.
i will use the path method.
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
Hi,i am in a problem to scan barcode without an active focus on a textbox. Can anyone help me? Please,do.
|
|
|
|
|
Scanning a barcode is basically the same as using keyboard. Wherever your focus is, that control will receive the input.
This property could be helpful to you: Form.KeyPreview Property[^]
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|