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. nginx+tomcat配置https

    nginx代理https后,应用redirect https变成http,很多页面报404.情况类似http://blog.sina.com.cn/s/blog_56d8ea900101hlhv.ht ...

  2. 游戏开发Camera之Cinematic Camera-深度

    人的视觉系统是二维的,它通过生理和心理的暗示来感知图像的深度,在现实世界中视觉系统会自动用深度线索depth cue来确定对象之间的距离游戏画面也是二维的,用x,y轴来定义,画面深度用z轴来定义,可以 ...

  3. UVA 11796 Dog Distance(向量)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31962 [代码] #include<cstdio> # ...

  4. Java 交换两个变量的数值

    一.参数传递方法 为解决标题问题,首先介绍参数传递方法.目前各类程序设计语言的参数传递方法主要有三种: 按值传递 按引用传递 按指针传递 其中按值传递表示方法(函数)接收的是调用者提供的变量的拷贝,不 ...

  5. [置顶] Linux高编之进程--------fork函数的同步与异步(兄弟子进程和父子孙进程示列)

    前面讲述的fork函数的基本用法,下面通过两个程序来说明fork函数同步与异步之间的关系: <1>通过fork函数实现在父进程下的四个兄弟子进程(即异步) : 函数实现代码: #inclu ...

  6. sql Server 发送邮件 错误类型及原因

    设置警报         在[常规项]中做以下设置 新建警报 设置警报名称 选择数据库 选择严重性     在[响应项]中可以做以下设置 选择要邮件通知的操作员 可以设置执行一个警报作业    在选项 ...

  7. Mysql性能优化那些事

    ​    ​对于全栈而言,数据库技能不可或缺,关系型数据库或者nosql,内存型数据库或者偏磁盘存储的数据库,对象存储的数据库或者图数据库--林林总总,但是第一必备技能还应该是MySQL.从LAMP的 ...

  8. JS:九宫格抽奖转盘实例

    工作需要,所以做了个抽奖转盘的插件,当然这里只做最简单的演示.可以用于取代一些flash抽奖程序. 机制说明: 1.通过定义lottery-unit来控制节点的个数及索引: 2.通过设置lottery ...

  9. springboot +spring security4 +thymeleaf 后台管理系统

    需求:一个后台管理系统,现在用的springboot 微框架比较多, 所以这里也使用了, 后台权限用 spring security ,之前以前觉得听复杂 . 后来发现还是蛮简单的, 看了源代码之后. ...

  10. android 36 线程通信

    安卓中一个程序跑起来叫进程,进程中至少有一个主线程.主线程用于处理用户的触摸操作和将触摸操作事件分发给响应的控件.如果进行消耗时间操作,下载,磁盘读取文件,不润许在主线程操作,只能在工作线程操作.主线 ...