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. Moving files programatically

Moving files programatically

Scheduled Pinned Locked Moved C#
helpquestion
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.
  • N Offline
    N Offline
    naglbitur
    wrote on last edited by
    #1

    Hi there, I hope someone can help me regarding a windows form program. I would like the user be able to press a button on the form and then an OpenFileDialog box opens, the user then selects a file that is at a certain location (similar to attaching a file when sending email). Then he presses another button on the form and a SaveFileDialog box appears letting the user select where he wants to save/move the file he just selected. How is this done? Can someone please help me? I hope I have explained this clearly enough. Thanks, F

    J 1 Reply Last reply
    0
    • N naglbitur

      Hi there, I hope someone can help me regarding a windows form program. I would like the user be able to press a button on the form and then an OpenFileDialog box opens, the user then selects a file that is at a certain location (similar to attaching a file when sending email). Then he presses another button on the form and a SaveFileDialog box appears letting the user select where he wants to save/move the file he just selected. How is this done? Can someone please help me? I hope I have explained this clearly enough. Thanks, F

      J Offline
      J Offline
      Judah Gabriel Himango
      wrote on last edited by
      #2

      Get the path of the file opened from the OpenFileDialog via openFileDialog.FileName. Store that file name in a variable, let's call it oldPath. In the save file dialog, after the user clicks OK, simply call System.IO.File.Move(oldPath, mySaveFileDialog.FileName);

      N 1 Reply Last reply
      0
      • J Judah Gabriel Himango

        Get the path of the file opened from the OpenFileDialog via openFileDialog.FileName. Store that file name in a variable, let's call it oldPath. In the save file dialog, after the user clicks OK, simply call System.IO.File.Move(oldPath, mySaveFileDialog.FileName);

        N Offline
        N Offline
        naglbitur
        wrote on last edited by
        #3

        Thanks for your answer. I see that File.Move takes as a parameter the source filename but what about the path? Does the dialog box take care of the path, where to save the file? Thanks again for your help. F

        J 1 Reply Last reply
        0
        • N naglbitur

          Thanks for your answer. I see that File.Move takes as a parameter the source filename but what about the path? Does the dialog box take care of the path, where to save the file? Thanks again for your help. F

          J Offline
          J Offline
          Judah Gabriel Himango
          wrote on last edited by
          #4

          When you retrieve the FileName from either the OpenFileDialog or the SaveFileDialog, it should contain both the path and file name, I believe.

          Tech, life, family, faith: Give me a visit. I'm currently blogging about: How 'bout a little guitar now? The apostle Paul, modernly speaking: Epistles of Paul Judah Himango

          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