Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Prompt user for Input

Prompt user for Input

Scheduled Pinned Locked Moved C#
sysadminquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thomas Toh
    wrote on last edited by
    #1

    // Make sure a duplicate file doesn’t exist. If it does, keep on appending an incremental numeric until it is unique string sFilename = System.IO.Path.GetFileName(myFile.FileName); string ans; while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename))) { Console.Write("Do you want to overwrite? (Yes/No)"); ans = Console.ReadLine(); Console.WriteLine(""); } lblOutput.Text = "File already existed. A duplicate file has been created"; the logic is upload file -> if file exists -> prompt for user input -> if yes -> overwrite -> if no prompt for user input for new file name the code is not finished.. but am i on the right path??

    C 1 Reply Last reply
    0
    • T Thomas Toh

      // Make sure a duplicate file doesn’t exist. If it does, keep on appending an incremental numeric until it is unique string sFilename = System.IO.Path.GetFileName(myFile.FileName); string ans; while (System.IO.File.Exists(Server.MapPath(sSavePath + sFilename))) { Console.Write("Do you want to overwrite? (Yes/No)"); ans = Console.ReadLine(); Console.WriteLine(""); } lblOutput.Text = "File already existed. A duplicate file has been created"; the logic is upload file -> if file exists -> prompt for user input -> if yes -> overwrite -> if no prompt for user input for new file name the code is not finished.. but am i on the right path??

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Seems a bit lost to me 1 - you're using server.mappath, but you're writing to the console, is this a server application or not ? 2 - sSavePath + sFilename, why not use Path.Combine ?

      Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      T 1 Reply Last reply
      0
      • C Christian Graus

        Seems a bit lost to me 1 - you're using server.mappath, but you're writing to the console, is this a server application or not ? 2 - sSavePath + sFilename, why not use Path.Combine ?

        Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        T Offline
        T Offline
        Thomas Toh
        wrote on last edited by
        #3

        1.sorry but what do you mean by server application? i'm doing asp.net c#.. images upload 2. oh path.combine works too? oh so ty lol

        C 1 Reply Last reply
        0
        • T Thomas Toh

          1.sorry but what do you mean by server application? i'm doing asp.net c#.. images upload 2. oh path.combine works too? oh so ty lol

          C Offline
          C Offline
          Christian Graus
          wrote on last edited by
          #4

          OK, then this is a disaster. Your console code plainly is not going to work on a website, now is it ? If you asked in the right forum, I'd have known for sure this was ASP.NET. If the code stood any chance of working, I may have figured it out. C# code runs on te server, not the client.

          Christian Graus Please read this if you don't understand the answer I've given you "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups