0

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.

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by __avd
0

>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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.