GUID, the abbreviation of "Global Unique Identifier", is a unique reference number used as an identifier in computer software.

GUIDs are usually stored as 128-bit values, and are commonly displayed as 32 hexadecimal digits with groups separated by hyphens, 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 do is to give every signature a unique name and save the file name in DB. GUID is perfect for my requirement.

Step1: Get the img bytes from DB

byte[] decodedImage = (byte[])reader["Signature"];

Step2: Transfer bytes to img

using (MemoryStream ms = new MemoryStream(decodedImage))
{
Image img = Image.FromStream(ms);
}

Step3: Give the img a unique name

using (MemoryStream ms = new MemoryStream(decodedImage))
{
Image img = Image.FromStream(ms);
var imgFileName = Guid.NewGuid().ToString() + ".png";
}

Step4: Save the file in system media folder and save the file name in DB

using (MemoryStream ms = new MemoryStream(decodedImage))
{
Image img = Image.FromStream(ms);
var imgFileName = Guid.NewGuid().ToString() + ".png";
fileName = imgFileName;
idArr = reader["Id"].ToString();
string path = Path.GetFullPath(SIGNATURE_PATH);
img.Save(path + imgFileName, System.Drawing.Imaging.ImageFormat.Png);
}
string sql = "UPDATE [Kiwi-UAT].[dbo].[StaffClockSignature]" +
"SET SignImageFile='" + fileName +
"' WHERE Id=" + idArr;
using(SqlCommand cmd = new SqlCommand(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#的更多相关文章

  1. Creating a Unique File Name

    If you are working with files or file attachments in PeopleCode, you will typically want to create a ...

  2. Unity3d导入工程出现错误“Creating unique file”的解决方法

    Unity3d导入工程出现错误“Creating unique file:creating file Temp/tempFile failed.Please ensure there is enoug ...

  3. Shell: how to list all db links in oracle DB to generate a flat file (生成dblink列表文件)

    如果数据库里有上百个DATABASE LINK, 而且同时要管理几十套这样的数据库,在日后改数据库用户密码时就要格外注意是否有DB LINK在使用,否则只改了LOCAL DB 的用户密码,没有级连修改 ...

  4. executing in nfs will not generate core dump file

    最近遇到了一个奇怪的问题. linux系统的pc搭建nfs server,开发板作为nfs client,开发板中全程root权限操作,执行的程序放到 nfs server 中 exports 出的目 ...

  5. Fedora 24中的日志管理

    Introduction Log files are files that contain messages about the system, including the kernel, servi ...

  6. mybatis反向生成sql,基本的增删改查

    用到的几个文件 MyBatisGeneratorProxy.java package com.timestech.wsgk.test.tools; import static org.mybatis. ...

  7. GUID概念

     GUID概念 GUID: 即Globally Unique Identifier(全球唯一标识符) 也称作 UUID(Universally Unique IDentifier) . GUID是 ...

  8. UUID GUID

    http://baike.baidu.com/link?url=xkck9gR5bzOx0oBKP1qNJwGGq3IO56V4i8cg9zTSpSDMVBMA0F7jr0AdkQTGyk7F0FGj ...

  9. codeforces 710E E. Generate a String(dp)

    题目链接: E. Generate a String time limit per test 2 seconds memory limit per test 512 megabytes input s ...

随机推荐

  1. Microsoft JScript 运行时错误: Automation 服务器不能创建对象

           var WshShell = new ActiveXObject('WScript.Shell')         WshShell.SendKeys( '{F11}');   问题: ...

  2. iOS类的继承关系

  3. java多线程编程(1) 线程的基本知识

    在前面研究过多线程与进程的区别. 这里在稍微总结一下: 进程:程序动态的一次执行过程. 线程:可以只是程序员的一部分的执行过程 每个进程有多个线程组成,在java程序中,至少两个线程一个是垃圾回收线程 ...

  4. GPG error: the public key is not available

    GPG error: The following signatures couldn't be verified because the public key is not available I h ...

  5. MySQL表设计基础

    MySQL表设计关于blog数据库中建立所有表的sql语句<一.>sql语句中 约束概念constraint concept1.1 实体完整性entity integrity(主键--唯一 ...

  6. Skype的故事:几乎所有风投都想投 犯罪分子洗钱必备

    Skype的故事:几乎所有风投都想投 犯罪分子洗钱必备 转载自: http://news.chinaventure.com.cn/11/7/1381032922.shtml 今年是 Skype 网络电 ...

  7. 创建oracle 密码文件

    orapwd file='$ORACLE_HOME/dbs/oratest' password=oracle entries=5 force=y; 说明:●FILE参数指定口令文件存放的全路径及文件名 ...

  8. Maven属性、profile和资源过滤

    Maven的六类属性 内置属性 主要有两个常用内置属性:${basedir}项目的根目录(包含pom.xml文件的目录),${version}项目版本 POM属性 用户可以使用该属性引用POM文件中对 ...

  9. UVaLive4043 UVa1411 Ants 巨人与鬼

    题意:给出平面上n个白点n个黑点,要求两两配对,且配对所连线段没有交点. 法一:暴力 随机一个初始方案,枚举任意两条线段如果有交点就改一下. 效率其实挺好的. 法二:二分图最佳完美匹配 显然没有交点的 ...

  10. HDU 1231 (13.12.2)

    Problem Description 给定K个整数的序列{ N1, N2, ..., NK },其任意连续子序列可表示为{ Ni, Ni+1, ..., Nj },其中 1 <= i < ...