GUID, the abbreviation of "Global Unique Identifier", is a unique reference number used as an Identifier in computer softw Is.
GUIDs is usually stored as 128-bit values, and is commonly displayed as + hexadecimal digits with groups separated by H Yphens, such as:
- 21ec2020-3aea-4069-a2dd-08002b30309d
My new task is to transfer the signature information, which directly saved as bytes[] data in DB. What I ' m gonna to does is to give every signature a unique name and save the file name in DB. The GUID is perfect for my requirement.
Step1:get the img bytes from DB
byte [] DecodedImage = (byte[]) reader["Signature"];
Step2:transfer bytes to img
using New MemoryStream (DecodedImage)) { = Image.fromstream (ms);}
Step3:give the img a unique name
using New MemoryStream (DecodedImage)) { = Image.fromstream (ms); var". png" ;}
Step4:save the file in System Media folder and Save the file name in DB
using(MemoryStream ms =NewMemoryStream (DecodedImage)) {Image img=Image.fromstream (MS); varImgfilename = Guid.NewGuid (). ToString () +". PNG"; FileName=Imgfilename; Idarr= reader["Id"]. ToString (); stringPath =Path.GetFullPath (Signature_path); img. Save (Path + imgfilename, System.Drawing.Imaging.ImageFormat.Png);
}
stringsql ="UPDATE [Kiwi-uat]. [dbo]. [Staffclocksignature]"+"SET signimagefile= '"+ FileName +"' WHERE id="+Idarr;using(SqlCommand cmd =NewSqlCommand (SQL, conn)) { Try{cmd. ExecuteNonQuery (); } Catch(System.Exception e) {Console.WriteLine (e.message); }}
- Tips:using These package at the begining of your file
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SqlClient; using System.IO; using System.Drawing;
Now I ' m got the PNG file in my folder and the FileName record in DB table ^_^:
Using GUID to generate the unique file name in C #