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. IE的表头固定/表头不动(使用expression)

    本文主要介绍在IE浏览器中,实现表头固定的一种方法.这种方法使用到了 IE 浏览器特有的 expression 方法. 表头固定DEMO1 主要代码: <style type="tex ...

  2. Google辅助类软件

    本博文的主要内容有 .Google辅助类软件的介绍 .重点首推!  Google软件精选管理器 1.Google辅助类软件的介绍 1.  Google软件精选管理器的下载和安装使用 2.  Googl ...

  3. C#添加资源的两种方式

    1.粘贴到项目Properties中的Resources.resx中 base.m_bitmap = Properties.Resources.MeasuredisTool; 2.添加已有资源中的bm ...

  4. git常用操作指令

    git操作master : 默认开发分支:origin : 默认远程版本库 添加远程仓库:git remote add [name] [url]  通常name为origin 克隆远程仓库:git c ...

  5. thinkphp 重定向redirect

    /** * URL重定向 * @param string $url 重定向的URL地址 * @param integer $time 重定向的等待时间(秒) * @param string $msg ...

  6. bzoj2822: [AHOI2012]树屋阶梯

    咦,这里有好多东西https://en.wikipedia.org/wiki/Catalan_number 每个矩形最多贡献一个拐角 枚举左上角的点和那个拐角是一个矩形 #include<cst ...

  7. Python - 字典(dict) 详解 及 代码

    字典(dict) 详解 及 代码 本文地址: http://blog.csdn.net/caroline_wendy/article/details/17291329 字典(dict)是表示映射的数据 ...

  8. 基于TCP的socket通信过程及例子

    Socket也叫套接字,用来实现网络通讯,通过调用系统提供的API,可以和远程的机子传输数据.Socket有很多种协议,而这篇文章主要讨论TCP部分的内容,也就是说后面说的内容主要是指TCP Sock ...

  9. Myeclipse2013 SVN安装方法

    1. 打开Help下的Install from Site 2. 弹出窗口,如下图: 3. 点击Add标签,如图: 在对话框Name输入Svn, URL中输入:http://subclipse.tigr ...

  10. [struts2学习笔记] 第一节 关于struts2的简单认知

    本文地址:http://blog.csdn.net/sushengmiyan/article/details/40298287 官方文档:http://struts.apache.org/releas ...