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. Windows Forms
  4. Getting File Path

Getting File Path

Scheduled Pinned Locked Moved Windows Forms
helpvisual-studioxmlquestion
4 Posts 3 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.
  • A Offline
    A Offline
    Ajeet mittal
    wrote on last edited by
    #1

    in application root i have a xml file. how can i get that file path. i am using to get file path @"..\..\file name,xml" when i run it from vs it is working. but when i Publish it it through an error. error shows file not found. how i will solve my problem can any one tell me. thanks

    C 1 Reply Last reply
    0
    • A Ajeet mittal

      in application root i have a xml file. how can i get that file path. i am using to get file path @"..\..\file name,xml" when i run it from vs it is working. but when i Publish it it through an error. error shows file not found. how i will solve my problem can any one tell me. thanks

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Ajeet mittal wrote:

      in application root i have a xml file. how can i get that file path. i am using to get file path @"..\..\file name,xml"

      That is not the application root. That is two levels above the application root.

      Ajeet mittal wrote:

      when i run it from vs it is working.

      That is because the XML file is most likely in your project, not the application root.

      Ajeet mittal wrote:

      how i will solve my problem

      Don't hard code file paths (relative or absolute) in your application. Put file paths in the config file and find out from there. Also, if the XML files are supposed to be in the application root folder then you might want to tell Visual Studio that so that it can copy the XML files to that location when you run your application. To do that, right click the XML file in the Solution Explorer. Select "Properties" in the context menu. In the Properties ensure that "Build Action" is set to "Content" and that "Copy to Output Directory" is set to either "Copy if newer" or "Copy Always"

      Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) - (part 3) My website | Blog

      A 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Ajeet mittal wrote:

        in application root i have a xml file. how can i get that file path. i am using to get file path @"..\..\file name,xml"

        That is not the application root. That is two levels above the application root.

        Ajeet mittal wrote:

        when i run it from vs it is working.

        That is because the XML file is most likely in your project, not the application root.

        Ajeet mittal wrote:

        how i will solve my problem

        Don't hard code file paths (relative or absolute) in your application. Put file paths in the config file and find out from there. Also, if the XML files are supposed to be in the application root folder then you might want to tell Visual Studio that so that it can copy the XML files to that location when you run your application. To do that, right click the XML file in the Solution Explorer. Select "Properties" in the context menu. In the Properties ensure that "Build Action" is set to "Content" and that "Copy to Output Directory" is set to either "Copy if newer" or "Copy Always"

        Recent blog posts: * Introduction to LINQ to XML (Part 1) - (Part 2) - (part 3) My website | Blog

        A Offline
        A Offline
        Ajeet mittal
        wrote on last edited by
        #3

        Thanks I do it what u told. but when i deploy my project.i still got error message. File not found. can u tell me the solution. what i have to do. thanking u

        A 1 Reply Last reply
        0
        • A Ajeet mittal

          Thanks I do it what u told. but when i deploy my project.i still got error message. File not found. can u tell me the solution. what i have to do. thanking u

          A Offline
          A Offline
          Ashfield
          wrote on last edited by
          #4

          Display the full file path and then see if the file is there. I'll bet it is a relative path and its wrong.

          Bob Ashfield Consultants Ltd

          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