Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

File Upload Web Service

Posted on March 28, 2013October 26, 2015 By David Kittell

This is a File Upload Web Service that can be a wrapper for a process in between.
Source code is an adaptation of this Microsoft article: HOW TO: Send and Receive Binary Documents by Using an ASP.NET Web Service and Visual C# .NET

Upload Client
UploadClient

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace UploadClient
{
    public partial class Form1 : Form
    {
        public static string sFile = "";

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            FileStream objfilestream = new FileStream(sFile, FileMode.Open, FileAccess.Read);
            int len = (int)objfilestream.Length;
            Byte[] mybytearray = new Byte[len];
            objfilestream.Read(mybytearray, 0, len);
            localhost.Service1 myservice = new localhost.Service1();

           myservice.SaveDocument(mybytearray, sFile.Remove(0, sFile.LastIndexOf("")));
            objfilestream.Close();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MemoryStream objstreaminput = new MemoryStream();
            FileStream objfilestream = new FileStream(sFile.Insert(sFile.LastIndexOf("."), "_processed"), FileMode.Create, FileAccess.ReadWrite);

            sFile = sFile.Replace(@"\", @"");

			//MessageBox.Show(sFile.Replace(@"", @"") + Environment.NewLine + sFile.Remove(0, sFile.LastIndexOf("") + 1));

            localhost.Service1 myservice = new localhost.Service1();
            int len = myservice.GetDocumentLen(sFile.Remove(0, sFile.LastIndexOf("") + 1));
            Byte[] mybytearray = new Byte[len];
            mybytearray = myservice.GetDocument(sFile.Remove(0, sFile.LastIndexOf("") + 1));
            objfilestream.Write(mybytearray, 0, len);
            objfilestream.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            // Browse for file to parse

            OpenFileDialog openFileDialog1 = new OpenFileDialog();

            openFileDialog1.InitialDirectory = "c:";
            openFileDialog1.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
            openFileDialog1.FilterIndex = 0;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                // Put filename and path in textbox1
                sFile = openFileDialog1.FileName.Replace(@"",@"");
                txtInputFile.Text = sFile;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }
    }
}
using System;
using System.IO;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;

namespace FileTransferWebService
{
	/// <summary>
	/// Summary description for Service1
	/// </summary>
	[WebService(Namespace = "http://tempuri.org/")]
	[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
	[System.ComponentModel.ToolboxItem(false)]
	public class Service1 : System.Web.Services.WebService
	{

		[WebMethod]
		public string HelloWorld()
		{
			return "Hello World";
		}

        [WebMethod]
        public bool SaveDocument(Byte[] docbinaryarray, string docname)
        {
            string strdocPath;
            strdocPath = "c:temp" + docname;
            FileStream objfilestream = new FileStream(strdocPath, FileMode.Create, FileAccess.ReadWrite);
            objfilestream.Write(docbinaryarray, 0, docbinaryarray.Length);
            objfilestream.Close();

            return true;
        }

        [WebMethod]
		public int GetDocumentLen(string docname)
        {
            string strdocPath;
			strdocPath = "c:temp" + docname;

            FileStream objfilestream = new FileStream(strdocPath, FileMode.Open, FileAccess.Read);
            int len = (int)objfilestream.Length;
            objfilestream.Close();

            return len;
        }


        [WebMethod]
		public Byte[] GetDocument(string docname)
        {
            string strdocPath;
			strdocPath = "c:temp" + docname;

            FileStream objfilestream = new FileStream(strdocPath, FileMode.Open, FileAccess.Read);
            int len = (int)objfilestream.Length;
            Byte[] documentcontents = new Byte[len];
            objfilestream.Read(documentcontents, 0, len);
            objfilestream.Close();

            return documentcontents;
        }

	}
}
Originally Posted on March 28, 2013
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

Code CSharp

Post navigation

Previous post
Next post

Related Posts

PHP WordPress – Use Radius Server Login

Posted on October 27, 2015November 19, 2015

Securing WordPress with Radius Server login. This project was created in mind to help secure WordPress but allow users an easier way to securely login without having to have a really long password to remember. While I do not go into creating the Radius server you can go to http://www.radiusdesk.com/getting_started/install_ubuntu_nginx…

Read More

LDAP LastLogonTimeStamp Conversion

Posted on April 8, 2014October 26, 2015

In working with LDAP timestamps I found this script very helpful to be able to test with. (Get-Date "2/1/2014").ToFileTime() [datetime]::FromFileTime("128752344000000000") Reference: http://jai-maharaj.blogspot.com/2012/01/test.html Originally Posted on April 8, 2014Last Updated on October 26, 2015 All information on this site is shared with the intention to help. Before any source code or…

Read More

GitLab – Folder Permissions Fix

Posted on November 29, 2016

If you’ve ran into a directory permissions problem with GitLab before this may be helpful. The code below is mostly based on GitLab documentation – https://docs.gitlab.com/omnibus/settings/configuration.html # Holds repositories directory sudo chown -R -v git:root /var/opt/gitlab/git-data sudo chmod -R -v 0700 /var/opt/gitlab/git-data # Holds git repositories sudo chown -R -v…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
  • Mac OS X Terminal - Parallels - Reset Windows User Password
  • PowerShell - IPv4 Range

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • Open On Screen Keyboard (OSK)
  • SQLite - Auto-Increment / Auto Generate GUID
  • Mac OS X Terminal - Parallels - Reset Windows User Password
  • PowerShell - IPv4 Range
©2025 David Kittell | WordPress Theme by SuperbThemes
 

Loading Comments...
 

You must be logged in to post a comment.