Getting
Started - LEADTOOLS Web Services in a VS.NET Windows Application Project
This topic cover how to include the LEADTOOLS
Host Web Services in Visual Studio .NET
Windows Application project.
Private imageService As New LEADImageService.ImageService Private fileService As New LEADFileService.FileService ' Change the following to be your username and password Private ReadOnly username As String = "username" Private ReadOnly password As String = "password" Private Sub BindGrid() Dim ds As DataSet = imageService.GetImageInfo( _ Nothing, _ Nothing, _ 1, _ LEADImageService.ImageGetInfoConstants.TotalPages, _ username, _ password) dgImages.DataSource = ds dgImages.DataMember = ds.Tables(0).TableName End Sub Private Sub UploadImage(ByVal fileName As String) Const bufferSize As Integer = 16 * 1024 Dim buffer(bufferSize - 1) As Byte Dim imageName As String = System.IO.Path.GetFileName(fileName) Dim fs As System.IO.FileStream = System.IO.File.OpenRead(fileName) Dim bytesLeft As Integer = CType(fs.Length, Integer) While (bytesLeft > 0) Dim bytesRead As Integer = fs.Read(buffer, 0, bufferSize) If bytesRead > 0 Then fileService.UploadFile( _ imageName, _ buffer, _ bytesRead, _ username, _ password) End If bytesLeft = bytesLeft - bytesRead End While fs.Close() fs = Nothing End Sub Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click Dim dlg As New OpenFileDialog dlg.Filter = "All files|*.*" If (dlg.ShowDialog(Me) = DialogResult.OK) Then UploadImage(dlg.FileName) BindGrid() End If End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load dgImages.ReadOnly = True BindGrid() End Sub private LEADImageService.ImageService imageService = new LEADImageService.ImageService(); private LEADFileService.FileService fileService = new LEADFileService.FileService(); // Change the following to your username and password private const string username = "username"; private const string password = "password"; private void BindGrid() { DataSet ds = imageService.GetImageInfo( null, null, 1, LEADImageService.ImageGetInfoConstants.TotalPages, username, password); dgImages.DataSource = ds; dgImages.DataMember = ds.Tables[0].TableName; } private void UploadImage(string fileName) { const int bufferSize = 16 * 1024; byte[] buffer = new byte[bufferSize]; string imageName = System.IO.Path.GetFileName(fileName); System.IO.FileStream fs = System.IO.File.OpenRead(fileName); int bytesRead; do { bytesRead = fs.Read(buffer, 0, bufferSize); if(bytesRead > 0) fileService.UploadFile(imageName, buffer, bytesRead, username, password); } while(bytesRead > 0); fs.Close(); fs = null; } private void btnUpload_Click(object sender, System.EventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Filter = "All files|*.*"; if(dlg.ShowDialog(this) == DialogResult.OK) { UploadImage(dlg.FileName); BindGrid(); } } private void Form1_Load(object sender, System.EventArgs e) { dgImages.ReadOnly = true; BindGrid(); } |
||