Guide for C# Upload TIFF File to Remote Database Core Document Formats Additional Features
| C# Imaging - Upload TIFF File to Remote DatabaseC# Code to Submit Captured Document to Database Repository
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.
vb.net insert image into pdf,
add text to pdf using itextsharp c#,
create pdf report from database in asp.net using vb.net,
convert pdf to image vb.net free,
reduce pdf file size in c#,
convert tiff to pdf c# itextsharp.
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.
convert pdf to html string c#,
convert pdf to text vb.net,
vb.net reduce pdf file size,
convert tiff to pdf c# itextsharp,
c# itextsharp html image to pdf,
convert excel to pdf vb.net,
add text to pdf vb.net.
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 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.
- Open the Visual Studios, and create new ASP.NET web site to the solution;
- 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.
- Open the Visual Studio 2005 or greater version;
- Create a new item to the website. This creates the database that can store the multi-paged document and associated metadata;
- Select SQL Database, and name it REImageDatabase.mdf;
- Select To add the database to the App Data folder in the web site when prompted;
- Create a table with the requiring fields and field types;
- Choose the default value of DateTimeCreated to getdate();
- Set the default value of PageCount to 0, and select ImageID as the primary key;
- 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.
- Add a new DataSet to your ASP.NET website project by clicking "Add New Item", and name the item just added REImageDatabase;
- Drag and drop the REImageDatabase table from the server explorer to the ImageDatabase.xsd window;
- Add two new queries by right-clicking on the ImageDatabaseTableAdapter and selecting AddQuery;
- 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.
- Right-click on the DotImage WebServer project and select Add New Item;
- Choose Web Service and name it ImageUpLoadService;
- Before you write the web service code, add a reference to RasterEdge DocImage;
- Start an upload folder in the website's root to store the documents as they are uploaded, and name the folder Upload;
- Add the following configuration setting to the configuration tag at the bottom of the web.config file.
<appSettings> <add key = "UploadPath" value="Upload"/> </appSettings> - 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; - 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; }
- 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.
- Create a new button in the ToolStrip named tsbUpload, and double click it to create the event handler;
- 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+
|