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. Can not create file using FileStream in release mode

Can not create file using FileStream in release mode

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

    Dear all, This is my situation: I try to create text file by using below code: using (FileStream fs = File.Create(path)){}; It runs ok at debug mode, file is create at [path]. But nothing happens at release mode. What wrong with this code? Pls. explain for me if you know.

    L 1 Reply Last reply
    0
    • N ndkit

      Dear all, This is my situation: I try to create text file by using below code: using (FileStream fs = File.Create(path)){}; It runs ok at debug mode, file is create at [path]. But nothing happens at release mode. What wrong with this code? Pls. explain for me if you know.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      you should put that in a try-catch and look at the Exception.ToString(). what is the exact content of path? does the path exist? (if relative, it could be different in release vs debug) Which Windows edition? :)

      Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

      Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

      N 1 Reply Last reply
      0
      • L Luc Pattyn

        you should put that in a try-catch and look at the Exception.ToString(). what is the exact content of path? does the path exist? (if relative, it could be different in release vs debug) Which Windows edition? :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

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

        Thank for your reply. About your question, I answer as below: - I also put the try-catch & look for Exception, but there is no exception. - The path is absolute path: C:\Program Files\MyFolder and it is existed. - I run in Window XP, VisualStudio 2003.

        D L 2 Replies Last reply
        0
        • N ndkit

          Thank for your reply. About your question, I answer as below: - I also put the try-catch & look for Exception, but there is no exception. - The path is absolute path: C:\Program Files\MyFolder and it is existed. - I run in Window XP, VisualStudio 2003.

          D Offline
          D Offline
          DaveyM69
          wrote on last edited by
          #4

          If you are trying to write to Program Files it could be a permissions issue. I would try another path that is definately going to accessible such as:

          Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)

          To get the path you're using ath the moment I would do it this way:

          string folderPath = Path.Combine(
          Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "MyFolder");

          I doubt that is related to your problem but may avoid problems in future.

          Dave
          Binging is like googling, it just feels dirtier. Please take your VB.NET out of our nice case sensitive forum. Astonish us. Be exceptional. (Pete O'Hanlon)
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

          1 Reply Last reply
          0
          • N ndkit

            Thank for your reply. About your question, I answer as below: - I also put the try-catch & look for Exception, but there is no exception. - The path is absolute path: C:\Program Files\MyFolder and it is existed. - I run in Window XP, VisualStudio 2003.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            ndkit wrote:

            Window XP

            That is OK, and will not add unexpected limitations to what you can and can't do.

            ndkit wrote:

            VisualStudio 2003

            So you are using .NET 1.1? I haven't used that for many years now, and I never will target it again. By all means, consider switching to .NET 2.0 (or higher). I'm not saying your problem is directly related, however 2.0 is much better than earlier versions, both in quality and functionality. If you don't have VS 2005/2008/2010 available, you might try using VS 2010 C# Express Edition, which is free and can be downloaded here[^]. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            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