We can transfer file using webservices, this is very easy. In my example i have taken bank statement pdf file. We have to give Account number, All ready we have PDFs in the particular folder (Ex: D:\AccountPDFFolders\" + AccountNumber + "_Statement.pdf";", Our example will take file from source and transfer through web service. Also, we can return status. like if status=1, file is there if not status =2(file does not exist)... Enjoy...
sdfdsf
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.IO; using System.Web.Services.Protocols; namespace viewPolicy { /// <summary> /// Summary description for WebService1 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. // [System.Web.Script.Services.ScriptService] public class WebService1 : System.Web.Services.WebService { [WebMethod(Description = "This is addtion one")] public RemoteFileInfo1 DownlodFile(int AccountNumber) { string accountStatementFolderPath = @"D:\AccountPDFFolders\" + AccountNumber + "_Statement.pdf"; Byte[] bytesData = null; FileInfo pdfFile = new FileInfo(accountStatementFolderPath); RemoteFileInfo1 objRemoteFile = new RemoteFileInfo1(); if (pdfFile.Exists) { try { FileStream fs = new FileStream(accountStatementFolderPath, FileMode.Open, FileAccess.Read); bytesData = new byte[fs.Length]; fs.Read(bytesData, 0, System.Convert.ToInt32(fs.Length)); fs.Close(); objRemoteFile.FileName = AccountNumber.ToString() ; objRemoteFile.fileByteStream = bytesData; objRemoteFile.fileStatus = "1"; return objRemoteFile; } catch (SoapException ex) { throw ex; } catch (Exception ex) { throw ex; } } else { objRemoteFile.fileStatus = "2"; objRemoteFile.FileName = accountStatementFolderPath; objRemoteFile.fileByteStream = bytesData; return objRemoteFile; } } } [Serializable] public class RemoteFileInfo1 : IDisposable { public string FileName; public string fileStatus; public byte[] fileByteStream; public void Dispose() { if (fileByteStream != null) { fileByteStream = null; } } } }
Post a Comment
Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.