I need to create a program that can read a file a user has selected, i'm trying to use this with the HtmlInputFile in Visual Studio.

The file then needs to be read and encoded, i've created a class that deals with the encoding and adds +13 onto each letter to encode it.

Encode.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;

namespace Coursework_Exercise2Web
{

    public class encode

    {

        private string encodedMessage;
        private char[] originalMessage = new char[100];

        public string encodeMess(string m)
        {
            originalMessage = m.ToCharArray();
            for (int i = 0; i < originalMessage.Length; i++)
            {
                originalMessage[i] = (Char)(originalMessage[i] + 13);
                encodedMessage += originalMessage[i];
            }
            return encodedMessage;
        }

        public string decodeMess(string m)
        {
            originalMessage = m.ToCharArray();
            for (int i = 0; i < originalMessage.Length; i++)
            {
                originalMessage[i] = (Char)(originalMessage[i] - 13);
                encodedMessage += originalMessage[i];
            }
            return encodedMessage;
        }
        
    }

}

I now want to know how to create in ASP.net a file upload so that user can select browse for a file and then the system will encode the text from the file they have uploaded. I've used the HTML input (file) however I need to try and program this to encode the users file.

Thank you.

>I've used the HTML input (file)

Add runat="server" attribute to this html tag,

...
 <input type="file" id="file1" runat="server"/>
 ...

and use file1.PostedFile.InputStream property to read the content of uploaded file in code-behind.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.