I'm just learning C# and I'm using MS Visual Studio for that and a website with tutorial stuff.

I've written my first little app which just does a simple calculation on some figures input by the user and outputs the result.

It is a console app at present.

Now I want it on a webpage so's I can put it on a site of mine.

But I can't figure out how to do it. Neither from Visual Studio screens, nor help, nor the tutorial....

Can anyone help?

regards,

ab :)

If your website is on Windows hosting, chances are you have the ability to utilize ASP.NET, which would allow you to write web pages/applications in C#/VB running on top of the .NET framework. You'd have to check with your service provider.

If your website is on Windows hosting, chances are you have the ability to utilize ASP.NET, which would allow you to write web pages/applications in C#/VB running on top of the .NET framework. You'd have to check with your service provider.

Ah, yes, well that's probably true, I probably can. But let's not worry about that at this stage. Let's just get something written that runs on my computer.

I feel confident I'll be able to run it on my ISP. Don't worry about that.

But here and now: how do I transfer it from the console app that it is right now, in Visual Studio, to a web-based app ( I guess that's what I'm asking for, rather than just an .exe that can be called from a web page) ?

I can run it and test it right here on my machine. I'm running IIS.

You're using Visual Studio.

Suggestion:

  1. Create a web form in your favourite language.
  2. Make a front end for the application using drag and drop controls. Inputs, outputs etc. Use a submit button to repaint the form with results.
  3. Test that out with trivial code (like just echo inputs back to the user).
  4. When you're happy with that, replace the back end with the code you already have, expressed as a method in your code behind file.
  5. Test that.

You can then test out other ways of doing it (if you wish), like

  1. Inline code instead of code behind
  2. MVC (need to load upo the tools)
  3. Web service (ASMX style or MCF style)

Note some of these are harder than others.

You'll soon find it's quicker to do than to explain.

If that doesn't work for you grab a sample online and inspect it. It's easy.

Good luck.

...

I feel confident I'll be able to run it on my ISP. Don't worry about that.

But here and now: how do I transfer it from the console app that it is right now, in Visual Studio, to a web-based app...

I can run it and test it right here on my machine. I'm running IIS.

Thank you for taking the trouble and having the patience to reply, Mike.

I'm doing what you suggest, as quickly as I can. Working through an online tutorial ( http://webproject.scottgu.com/CSharp/MasterPages/MasterPages.aspx ) .

So incredibly complex for something so simple.

I think that somewhere within what has already been covered there's examples of the simple, basic 'input and output' that I require. But I'll have to go over it all again to find them.

You know, there's only two commands in the whole of my code, I think. Just an input and an output. I should have posted the code, maybe, and asked people for the speediest way to get it onto a web page.

This incredible complexity I'm finding in this tutorial is, I suppose, on the way to developing incredible power for constructing future incredible apps that are full of bells and whistles.

But, oh my god, I don't want/need that....

I will post the code.

// Namespace Declaration
using System;

// Program start class
class InteractiveWelcome
{
    // Main begins program execution.
    public static void Main()
    {
        double length,width,depth,volume,dryvolume;
        double sand, gravel, cement;
        string input;
        // Write to console/get input
        Console.Write("    What is your name?: ");
        Console.Write("    Hello, {0}! ", Console.ReadLine());
        Console.WriteLine("    Welcome to Dave's concrete calculator!");
       string name = Console.ReadLine();
        Console.Write("    Hello, {0}! ", name);
        
        Console.WriteLine("    Type in a length:");
        input = Console.ReadLine();
        length = double.Parse(input);
        //Console.WriteLine(length);

        Console.WriteLine("    Type in a width:");
        input = Console.ReadLine();
        width = double.Parse(input);
        //Console.WriteLine(length);

        Console.WriteLine("    Type in a depth:");
        input = Console.ReadLine();
        depth = double.Parse(input);
        //Console.WriteLine(length);

        volume = length * width * depth;

        Console.WriteLine("    A slab " + length + " by " + width + " by " + depth + " will require : ");
        Console.WriteLine();
        Console.WriteLine("     a volume of  : " + volume + " cubic metres of concrete.");
        Console.WriteLine();

        dryvolume = volume * 1.6;

        Console.WriteLine("This is a volume of " + dryvolume + " cu metres dry material.");
        Console.WriteLine();

        sand = dryvolume / 6;
        gravel = dryvolume / 3;
        cement = dryvolume / 6;

        Console.WriteLine("        For a 1:2:3 Mix:");
        Console.WriteLine();

        Console.WriteLine("    Sand : {0:##.###}.  cu metres",sand);
        Console.WriteLine();
        Console.WriteLine("    Gravel : {0:##.###}.  cu metres", gravel);
        Console.WriteLine();
        Console.WriteLine("    Cement : {0:##.###}.  cu metres", cement);
        Console.WriteLine();
        
    }
}

There it is. That's all it is. I'll add more and tart it up a bit but right now all I want to do it put that on a page. And to try and be a modern guy I'm trying to use C# and Visual Studio instead of just having my page call a C routine using the CGI.

Thanks again for your help, Mike. You should see the snotnose reply I got from some poor dude who needs-to-get-a-life on another forum. :)

ab


You're using Visual Studio.

Suggestion:

  1. Create a web form in your favourite language.
  2. Make a front end for the application using drag and drop controls. Inputs, outputs etc. Use a submit button to repaint the form with results.
  3. Test that out with trivial code (like just echo inputs back to the user).
  4. When you're happy with that, replace the back end with the code you already have, expressed as a method in your code behind file.
  5. Test that.

You can then test out other ways of doing it (if you wish), like

  1. Inline code instead of code behind
  2. MVC (need to load upo the tools)
  3. Web service (ASMX style or MCF style)

Note some of these are harder than others.

You'll soon find it's quicker to do than to explain.

If that doesn't work for you grab a sample online and inspect it. It's easy.

Good luck.

Don't be discouraged by the apparent complexity.

It's really easy to do. A few minutes and it's working.

I haven't the time to take this further but I find that throwing together a quick Winforms or asp.net page are so natural that I barely notice doing it.

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.