Guide for C#
Upload TIFF File to Remote Database
Core Document Formats
Additional Features

C# Imaging - Upload TIFF File to Remote Database

C# Code to Submit Captured Document to Database Repository

Visual C#
Home > .NET Imaging SDK > C# > Tutorial: Upload TIFF to Remote Database
If this is your first time to use our DocImageSDK, we strongly suggest you reading How to Start first!

With the most comprehensive Rasteredge .NET Imaging Web Viewer DLL, users are competent to open, view, navigate and process any supporting image and document file with zero plugin and footprint in ASP.NET and JavaScript controls. Beside our powerful document viewer functions, users are supposed to create your own customized image and document viewer in Windows project. In the C#.NET capturing document from scanning client, we talked about how to create users application interface and capture multi-page document from any supported scanner in details.
Related .net document control helps:
asp.net document viewer open source: EdgeDoc:ASP.NET Document Viewer C# Control: Open, view, annotate, redact, convert documents online in C#, VB.NET, AS...
c# asp.net text file viewer: ASP.NET Text file viewer in MVC, WebForms: Open, view, annotate, convert txt files in C# ASP.NET
c# asp.net word document viewer: ASP.NET Office Word Document Viewer: view Word doc files online using C# in ASP.NET MVC web applications
asp.net pdf document viewer c#: ASP.NET PDF Document Viewer in C#: open, display, view, annotate, redact Adobe PDF files online in ASP.NET MVC & WebForm...
asp.net edit pdf text using c#: ASP.NET PDF Text Edit Control: online edit PDF text content using C# ASP.NET
c# asp.net tiff viewer: ASP.NET Tiff Viewer: view, annotate multipage Tiff images in ASP.NET MVC, WebForms using C# Control
asp.net annotate pdf using c#: ASP.NET Annotate PDF Control: annotate, comment, markup PDF document online using ASP.NET C#
However, if the user is an enterprise organization, the documents will need to be stored in a central database. In this tutorial article, users are showed how to configure web services to transmit images from a scanner client application to a web service and into a SQL database. Users can get the detailed guide on how to upload the captured multiple pages documents to center database repository by using C# sample code within Rasteredge .NET Imaging Document Viewer SDK.
Main Steps on Submitting Captured Documents
  • Start the ASP.NET Web Project in C#.NET
  • Create the SQL Database in C#.NET
  • Create the Data Abstraction Layer in C#.NET
  • Create the Web Service in C#.NET
  • Connect the Capture Client to the Web Service in C#.NET
  • Show Progress While the Document Loads in C#.NET
C#.NET Code to Upload Captured Document
Please refer to following detailed procedures to submit the captured multi-page document to the center database repository by using RasterEdge C#.NET Imaging Document Viewer SDK.

Create the ASP.NET Web Project

Before creating this project, please install the Web Service Enhancements 3.0 for Microsoft.NET. This enables the MTOM protocol to efficiently send binary image data from the capture client to the web service. Or you can use Windows Communication Foundation (WCF). This approach is not covered in this lesson.
  1. Open the Visual Studios, and create new ASP.NET web site to the solution;
  2. Right-click on the Website project and select WSE Settings 3.0.

Create the SQL Database

Following guide will show how to create the SQL database.
  1. Open the Visual Studio 2005 or greater version;
  2. Create a new item to the website. This creates the database that can store the multi-paged document and associated metadata;
  3. Select SQL Database, and name it REImageDatabase.mdf;
  4. Select To add the database to the App Data folder in the web site when prompted;
  5. Create a table with the requiring fields and field types;
  6. Choose the default value of DateTimeCreated to getdate();
  7. Set the default value of PageCount to 0, and select ImageID as the primary key;
  8. Create and table and save it as REImageDatabase.

Create the Data Abstraction Layer

In this step, you will upload the captured documents to the central database repository.
  1. Add a new DataSet to your ASP.NET website project by clicking "Add New Item", and name the item just added REImageDatabase;
  2. Drag and drop the REImageDatabase table from the server explorer to the ImageDatabase.xsd window;
  3. Add two new queries by right-clicking on the ImageDatabaseTableAdapter and selecting AddQuery;
  4. Use the SQL that follows to name the first query CreateRecord.

Create the Web Service

This part is also for submitting the captured documents to a central database repository.
  1. Right-click on the DotImage WebServer project and select Add New Item;
  2. Choose Web Service and name it ImageUpLoadService;
  3. Before you write the web service code, add a reference to RasterEdge DocImage;
  4. Start an upload folder in the website's root to store the documents as they are uploaded, and name the folder Upload;
  5. Add the following configuration setting to the configuration tag at the bottom of the web.config file.
    <appSettings>
    <add key = "UploadPath" value="Upload"/>
    </appSettings>
  6. Call the namespace as shown below:
    using System.IO;
    using RasterEdge.Imaging;
    using RasterEdge.Imaging.Codec;
    using System.Configuration;
    using System.Security.Cryptography;
    using ImageDatabaseTableAdapters;
  7. Create the StartUpload() method:
    public string StartUpload(string name)
    {
    Guid guid = Guid.NewGuid();
    string uid = guid.ToString();
    using (Stream stream = File.Create(Path.Combine(_uploadPath, uid)))
    {
    }
    using (ImageDatabaseTableAdapter ta = new ImageDatabaseTableAdapter())
    {
    ta.CreateRecord(guid, name);
    }
    return uid;
    }

  8. Use following code to call AppendChunk() from the client until the entire document is uploaded.
    public void AppendChunk(string uid, byte[] buffer, long offset)
    {
    string filename = Path.Combine(_uploadPath, uid);
    if (File.Exists(filename))
    {
    // open a file stream and write the buffer. Don't open with
    FileMode.Append because the transfer may wish to start at a different point
    using (FileStream fs = new FileStream(filename, FileMode.Open,
    FileAccess.ReadWrite, FileShare.Read))
    {
    fs.Seek(offset, SeekOrigin.Begin);
    fs.Write(buffer, 0, buffer.Length);
    }
    }
    else
    {
    throw CustomSoapException("Error Uploading File: cached file is
    missing"
    );
    }

Connect Image Capturing Client to the Web Service

This part main includes the procedures on how to connect the capture client to the web service. But before you do this, you need to save the ImageUploadService file, add a web reference to ImageUploadService just created and finally name that connection DotImageWebServer.
  1. Create a new button in the ToolStrip named tsbUpload, and double click it to create the event handler;
  2. Create a private constant, _chunkSize that defines the size of each chunk to be sent to the service, and click OK for the event handler and setting the dialog result.

How to Create the Upload Code

After all the above steps, it's time for creating the upload code. The code will be used at the point where the image is saved to a stream, and then uploaded to the web service. Following demo codes are for saving the document to a multi-page TIFF.
using System.Security.Cryptography;

private void tsbUpload_Click(object sender, EventArgs e)
{
InputForm dialog = new InputForm();
if (dialog.ShowDialog(this) == DialogResult.OK)
{
string tempPath = System.IO.Path.GetTempPath();
DotImageWebServer.ImageUploadService service = new
DotImageWebServer.ImageUploadService();
service.Credentials = System.Net.CredentialCache.DefaultCredentials;
string guid = service.StartUpload(dialog.Title);
string filename = Path.Combine(tempPath, guid);
byte[] hash = null;
try
{
TiffEncoder encoder = new TiffEncoder(TiffCompression.Default);
using (Stream stream = File.Create(filename))
{
documentViewer1.Save(stream, encoder);
stream.Seek(0, SeekOrigin.Begin);
//get hash
MD5CryptoServiceProvider md5 = new
MD5CryptoServiceProvider();
hash = md5.ComputeHash(stream);
stream.Seek(0, SeekOrigin.Begin);
//read stream
long streamLength = stream.Length;
byte[] buffer = new byte[_chunkSize];
int currentOffset = 0;
int bytesRead = 0;
do
{
bytesRead += stream.Read(buffer, 0, _chunkSize);
service.AppendChunk(guid, buffer, currentOffset);
currentOffset = bytesRead;
} while (bytesRead < streamLength);
}
}
finally
{
if (guid != null)
{
service.FinishUpload(guid, hash);
File.Delete(filename); //delete temp file
}
}
}
}


Recommend this to Google+


RasterEdge.com is professional provider of ASP.NET MVC Document Viewer, ASP.NET PDF Viewer, MVC PDF Viewer document, content and imaging solutions, available for ASP.NET AJAX, Silverlight, Windows Forms as well as WPF. We are dedicated to provide powerful & profession imaging controls, PDF document, image to pdf files and components for capturing, viewing, processing, converting, compressing and stroing images, documents and more.

©2000-2017 Raster Edge.com