dcsimg
Results 1 to 31 of 31

Thread: [RESOLVED] Copy to Output Directory: Copy Always question

  1. #1

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Resolved [RESOLVED] Copy to Output Directory: Copy Always question

    1- Put Book1.xlsx file to the Solution Explorer by following Add > Existing Item

    2- Set properties of Book1.xlsx in the Solution Explorer like following ;
    Build Action: Content
    Copy to Output Directory: Copy Always

    3- Run this project and see if Book1.xlsx file is copied to the the Debug folder

    4- Close this project.

    5- Open Book1.xlsx file manually by finding it in the Debug folder. Keep Book1.xlsx file open.

    6- Run this project again and see the following error;

    Code:
    Could not copy "C:\Users\onsuz\OneDrive\Desktop\WpfApplication1\WpfApplication1\Book1.xlsx" to "bin\Debug\Book1.xlsx". Beginning retry 1 in 1000ms. The process cannot access the file 'bin\Debug\Book1.xlsx' because it is being used by another process.
    As you can see if a curious person opens Book1.xlsx file manually before my application start then my application crashes.

    Do you have any solution?
    Last edited by Kram Kramer; Nov 7th, 2019 at 08:57 AM.

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: Copy to Output Directory: Copy Always question

    Users will not be affected by this, because it is part of the Build process (creating an executable from your code etc), and not running the application.

    You should find that it doesn't happen if you build and run your app inside Visual Studio, then do step 5 above, and then (without changing any code etc or doing a Build) run it again using the start button (or the debug menu).

  3. #3

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Thanks a lot. Solved.

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,319

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    As suggested, this has got nothing to do with your application. It's the build process that is failing, not the running of your application. Also, you wouldn't have this issue if you used `Copy if Newer` because the build process wouldn't try to overwrite the file in the output folder unless the one in the project folder was newer, which it on't be unless you have made changes to it since you last copied or made changes to the one in the output folder.

    That said, you will find that, once your app is deployed, it will not be able to do certain things with that file if the user has opened the file in Excel themselves. For that reason, you should make sure that any attempt to open that file in code are wrapped in an exception handler.

  5. #5

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    1- I put Book1.xlsx file to the Solution Explorer by doing following Add > Existing Item

    2- I set properties of Book1.xlsx in the Solution Explorer like following ;
    Build Action: Content
    Copy to Output Directory: Copy Always (or Copy if Newer)

    3- I start my application. (Whenever I start my application Book1.xlsx file is copied from Solution Explorer to Debug Folder)

    4- I dont use Book1.xlsx file in the Debug Folder yet.

    5- A bad person goes to Debug Folder and replaces Book1.xlsx file with another excel file during my application runs.

    6- I press to Button1 in order to get one copy of Book1.xlsx in the Desktop (The following code copies Book1.xlsx file from Debug Folder to Desktop.)

    Code:
    Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
    IO.File.Copy(sourceFileName:=IO.Path.Combine(New IO.FileInfo(Reflection.Assembly.GetExecutingAssembly.FullName).DirectoryName, "Book1.xlsx"),
               destFileName:=My.Computer.FileSystem.SpecialDirectories.Desktop & "\Book1.xlsx")
    End sub
    That means Book1.xlsx file in the desktop is the file which a bad person puts!!!

    How about this bad scenario?
    Last edited by Kram Kramer; Nov 8th, 2019 at 06:32 AM.

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Reading/writing files (including copying a file) is likely to have errors, especially if user-based locations like the Desktop are involved.

    By default your application will crash when an error (aka exception) occurs, hence jmcilhinney's advice to use an exception handler around code that works with files. An exception handler allows you to deal with the errors in a graceful way (such as showing the user an appropriate message), rather than crashing.

    In this case you could do something like this:
    Code:
    Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
      Try
          IO.File.Copy(sourceFileName:=IO.Path.Combine(New IO.FileInfo(Reflection.Assembly.GetExecutingAssembly.FullName).DirectoryName, "Book1.xlsx"),
               destFileName:=My.Computer.FileSystem.SpecialDirectories.Desktop & "\Book1.xlsx")
      Catch ex as Exception
         MessageBox.Show("Could not copy the file due to the following problem:" & Environment.Newline & ex.Message)
      End Try 
    End sub

    edit: If you mean that you are concerned that somebody might put a dodgy file in the application folder (so it gets copied to the desktop when Button1 is clicked), that is possible - but very unlikely if your application is stored in a protected location like ProgramFiles, as it is much harder to modify/delete/overwrite files there.
    Last edited by si_the_geek; Nov 8th, 2019 at 06:36 AM.

  7. #7

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Are you sure a bad person can not intervene to Debug Folder if I put my application to the ProgramFiles?


    Do you know any code which copies Book1.xlsx file from Solution Explorer to Desktop directly?
    Last edited by Kram Kramer; Nov 8th, 2019 at 07:00 AM.

  8. #8
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    The folders you use in Visual Studio (like Debug and Release, as well as other things in Solution Explorer) do not exist on the users computer.

    What does exist on the users computer is your application folder (which is basically a copy of the Release folder or the Debug folder), plus anything else you set up in your installer.

    A bad person can edit/replace your files and your program. If your application folder is in ProgramFiles, they can only do it if they have Admin rights on the computer... but if they have Admin rights, there is nothing you can do to stop them anyway.

    In terms of code, what you currently have (plus an appropriate exception handler) is probably the best thing for you.

  9. #9
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,097

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    why don't you password protect the Excel File ?

    or password protect a Range
    this would protect in Sheet2 the Range B1:B10
    Code:
     WorkSheets(2).Cells.Locked = False
            WorkSheets(2).Range("B1:B10").Locked = True
            WorkSheets(2).Protect("mypass")
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  10. #10

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Whenever I start my application Book1.xlsx file is copied from Solution Explorer to Debug Folder automatically.

    I want to do same action with manuel code. So, do you know any vb.net code which copies Book1.xlsx file from Solution Explorer to Debug Folder when user click a Button?

    The following C# code is taken here: https://stackoverflow.com/questions/...t-compile-time

    Code:
    copy $(ProjectDir)Configuration\* $(ProjectDir)$(OutDir)
    Do you know vb.net version of the above code?


    Supporting link:
    https://docs.microsoft.com/tr-tr/cpp...N&view=vs-2019
    Last edited by Kram Kramer; Nov 8th, 2019 at 10:26 AM.

  11. #11
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    837

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Either you are very confused or not clearly explaining what you are trying to accomplish.

    Solution Explorer, and the Debug Folder are present on the developer's (your) system. The end user has none of that. Unless what you are distributing is source code that you are expecting the end user to be compiling with their own version of Visual Studio, which I can't imagine is the case.

    Good luck.

  12. #12

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by OptionBase1 View Post
    Either you are very confused or not clearly explaining what you are trying to accomplish.

    Solution Explorer, and the Debug Folder are present on the developer's (your) system. The end user has none of that. Unless what you are distributing is source code that you are expecting the end user to be compiling with their own version of Visual Studio, which I can't imagine is the case.

    Good luck.
    Debug folder means Release Folder.
    So, the end user dont have Release Folder?

  13. #13
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,505

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by Kram Kramer View Post
    Debug folder means Release Folder.
    So, the end user dont have Release Folder?
    No. They will not have a debug folder, nor will they have a release folder. What they will have is the application folder where it was installed. You need to stop thinking about it in terms of how you see it from the IDE because that's not how they will see it. The only thing that is relevant is the relative folder from the location where the application resides... WHERE that application is, is irrelevant. All you need to know is where your file is, which should be Application.StartupFolder (if I remember my folders right) and where it needs to be (which is My.Computer.FileSystem.SpecialDirectories.Desktop).

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  14. #14

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    I dont care what the folder name is.

    I care if end user is able to delete/replace Book1.xlsx file which is copied whenever my application starts.

    So, is it possible that end user is able to delete/replace Book1.xlsx file during my application is running?
    Last edited by Kram Kramer; Nov 8th, 2019 at 10:42 AM.

  15. #15
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,505

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by Kram Kramer View Post
    I dont care what the folder name is.

    I care if end user is able to delete/replace Book1.xlsx file which is copied whenever my application starts.

    So, is it possible that end user is able to delete/replace Book1.xlsx file during my application is running?
    Sure.... IF they know where to find it... Now.. if you want to make it so they can't find it... what you could do it add it as an Embeded Resource, which would then compile it into the EXE... you would then need to extract it from the reosurces area first, then copy it where you need it to... If it were me, I'd extract it to the windows temp folder with a random name, then copy it to the desktop, or what ever flder you have access to that makes it workable.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  16. #16
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    The users can delete/replace files if you store them outside of protected locations like ProgramFiles (so use ProgramFiles or similar).

    If they have Admin rights on the computer, they can also delete/replace files in ProgramFiles etc (including your application itself), and you cannot stop that.


    Using a more complex method like tg's suggestion makes it more complicated for them to do it (which will stop many people), but there are people who can work around any extra protection you can add.

  17. #17

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    si_the_geek,

    Please look at #10 post.

    Do you know any vb.net code which copies Book1.xlsx file from Solution Explorer to Debug Folder when user click a Button?

    Please note that, Debug Folder = Release Folder = Application Folder
    Last edited by Kram Kramer; Nov 8th, 2019 at 11:24 AM.

  18. #18
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,505

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by Kram Kramer View Post
    si_the_geek,

    Please look at #10 post.

    Do you know any vb.net code which copies Book1.xlsx file from Solution Explorer to Debug Folder when user click a Button?
    A thousand slaps with a wet noodle.... don't make me break out the trout!
    YOu are not listening are you? You're worried about the Solution Explorer? WHY? How is the USER going to get that? Are you planning on shipping your project and all the code to your users? OR are you going to build your project, and create an installer that they then use to install the app on their computer? If it's the former then I pray for your insanity. If the latter then wh the F are you worried about things? You've been told multiple times not to worry about copying from Solution Explorer to the Debug folder by user click because that's not a Runtime issue.. that is a BUILD issue. Period. Full Stop. End of Story. End. Of. Story. You're paranoid about something, I'm not sure what. But it's getting in the wayof reasonable and logic and you're not seeing reality clearly. So just stop. Just STOP. Take a deep breath. The users are NOT going to have anything in your Solution Explorer folders... so tyring to copy from that is useless.... don't worry about that... all they are going to have is what you install on their computer, which should ONLY BE what is in EITHER Release OR Debug, depending on which folder you select (which is completely up to you) and you copy to thei computer, or use as the source for an installer. Once it's on their machine it doesn't exist as Debug or Release but as what ever. I could be Qwertyo r Quijibo or even Jimbo, doesn't matter. But it will contain your file... from there you can copy it to where ever you need to, even if it's the user's desktop. Yes, that means, IF they find the folder.... IF the find it... IF IF IF... but only if they go looking for it... is that a problem? Truly.... ask yourself that .... Is it really a problem.... or are you just being paranoid? There does have to be a point where you realize that there is only so much you can do. Still... if it truly is an issue... there are way to protect it... and I gave you one... add it as an embedded resource... extract it, then copy it...
    But for the love of all things ENIAC, stop worrying about copying from Solution Explorer to Debug Folder


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  19. #19
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,239

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    You almost certainly don't need code for that, because neither of those folders exist on the users computer.

    Your program should never care about what is in Solution Explorer - because that is just the location of code files etc that are used to build the program, not the program itself.

    The files like Book1.xlsx will be in the Application folder. On the users computer that will probably be in ProgramFiles (perhaps "c:\ProgramFiles\YourAppName"). On your computer (when your program is "installed") that will be wherever you have installed/copied it. On your computer when running in Visual Studio, it will be in either the Debug folder or the Release folder.

  20. #20
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,097

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by techgnome View Post
    .... or are you just being paranoid? Solution Explorer to Debug Folder

    -tg
    paranoid is the right word
    @Kram
    does your program have a Database ? what if the User's want to mess with that.
    I showed you an option to protect(to a certaint extent) the Excel file, if they want to find the File they will find it
    ok the found it and opend it, so Protect at least the content of the File

    what does this Excel file do anyway ?
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  21. #21

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    I am not paranoid...

    There is no risk for me if the User trying to mess my application...

    I just want to understand if Visual Studio is poorly designed or not...

    If the User is able to find original Book1.xlsx and replace it with another excel file this means that my application is not able to copy original Book1.xlsx file to the User's Desktop...
    Last edited by Kram Kramer; Nov 8th, 2019 at 02:58 PM.

  22. #22
    Fanatic Member
    Join Date
    Nov 2017
    Posts
    837

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by Kram Kramer View Post
    I am not paranoid...

    There is no risk for me if the User trying to mess my application...

    I just want to understand if Visual Studio is poorly designed or not...

    If the User is able to find Book1.xlsx and replace it with another excel file this means that my application is not able to copy original Book1.xlsx file to the User's Desktop...
    If your application relies on the user having an Excel file on their desktop named Book1.xlsx, I would worry more about if your own application is what is poorly designed.


    Your question still has some unanswered questions. I'm going to assume the following for the sake of simplicity:

    *** My understanding of your concern

    Your program is installed into C:\Program Files\KramProg\

    Inside that folder, there is KramProg.exe and Book1.xlsx.

    You are worried that if someone replaced Book1.xlsx inside of C:\Program Files\KramProg\ with some other Excel file, then when using KramProg.exe and clicking the "Copy Spreadsheet" button, your program copies C:\Program Files\KramProg\Book1.xlsx to the user's desktop folder - except the user replaced Book1.xlsx in C:\Program Files\KramProg\ with their own spreadsheet, and so the file Book1.xlsx that is copied to the user's desktop isn't the file you intended to be copied to their desktop.

    *** End of my understanding

    If that understanding is correct, how, exactly, is Visual Studio at fault in any plausible way?

  23. #23
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,505

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    That's not a poor design issue of Visual Studio ... which has been around and working like this for.... over 20 years... that's a poor design issue on YOUR application. If your app is reliant on files being in a certain spot in order to operate (and whose app doesn't) then that's what you do... you make sure you get those files to where they need to be. If some user tinkers with those files, that's their problem. Do you think Ford worries about what would happen if someone puts water in their gas tank? No. That becomes a problem for the car owner.

    And I gave you a solution on how to prevent that from happening. I'll mention it one more time, then I am done with this thread. Make the document an Embedded Resource. Extract it to the Windows Temp folder.Copy it from the Temp folder to the desktop and use it from there. Or.... don't even copy it to the desktop.... just use it from the temp folder... then the user doesn't even see or know about it.


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  24. #24

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by OptionBase1 View Post
    If that understanding is correct, how, exactly, is Visual Studio at fault in any plausible way?
    Your understanding is correct.


    A developer puts Book1.xlsx file to the Solution Explorer then deploy the application.

    Whenever the User runs the application then Visual Studio copies Book1.xlsx file from Solution Explorer to Output Folder.

    Why Visual Studio copies Book1.xlsx file from Solution Explorer to Output Folder and reveal Book1.xlsx file?

    I wish Visual Studio is able to copy original Book1.xlsx file to the User's desktop without revealing.
    Last edited by Kram Kramer; Nov 8th, 2019 at 04:20 PM.

  25. #25
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,319

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    OMG! You are not listening and you seem to have no idea what you're doing. How could Visual Studio possibly copy anything to an end user's desktop? Visual Studio is on your machine, not on the machine of the person running your app.

    You build your app in Visual Studio from the source files in your project folder and that output is placed in an output folder. What the output includes depends on the project, but it may be an executable file, a configuration file, content files or whatever. The output folder will be 'bin\Debug' by default for a Debug build and 'bin\Release' for a Release build. What you then do with that output is up to you.

    If you are just going to copy the output files to the end user's machine then it's up to you - or them - to put the files where they need to go. If you want a file on the desktop, put it on the desktop. Of course, if you're worried about people changing or deleting files, the desktop is the worst place to put them.

    Alternatively, you can create an installer for your app and it can do whatever you want it to. For instance, the installer can copy a file to the desktop. Visual Studio creates the installer but the installer places the files on the end user's machine.

    The question really is why do you think you need to do something different to what millions of developers the world over have been doing for years?

  26. #26

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Hi jmcilhinney,

    A developer puts Book1.xlsx file to the project and then deploy the application.

    Whenever the User runs the application one copy of Book1.xlsx file shows up in the Output Folder.

    Everyone can easily replace/delete Book1.xlsx file from Output Folder.

    Why Book1.xlsx file shows up in the Output Folder? That is the question...

    So if someone deletes Book1.xlsx file from Output Folder then following code throws an Exception.


    Code:
    Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
      Try
          IO.File.Copy(sourceFileName:=IO.Path.Combine(New IO.FileInfo(Reflection.Assembly.GetExecutingAssembly.FullName).DirectoryName, "Book1.xlsx"),
               destFileName:=My.Computer.FileSystem.SpecialDirectories.Desktop & "\Book1.xlsx")
      Catch ex as Exception
         MessageBox.Show("Could not copy the file because someone has deleted the Book1.xlsx")
      End Try 
    End sub
    I wish someone has no chance to delete Book1.xlsx file from Output Folder.
    Last edited by Kram Kramer; Nov 9th, 2019 at 03:32 AM.

  27. #27
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,097

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Hi,

    I asked in Post#20 what this Excel File is for, or what does it do ?

    perhaps there can be another solution
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  28. #28

    Thread Starter
    Addicted Member Kram Kramer's Avatar
    Join Date
    Dec 2016
    Posts
    130

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by ChrisE View Post
    Hi,

    I asked in Post#20 what this Excel File is for, or what does it do ?

    perhaps there can be another solution
    The problem is the User or Someone else is able to delete Book1.xlsx file.

    I dont want the User or Someone else is able to delete Book1.xlsx file.

    I dont want the following code throws an exception.

    Code:
    Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
      Try
          IO.File.Copy(sourceFileName:=IO.Path.Combine(New IO.FileInfo(Reflection.Assembly.GetExecutingAssembly.FullName).DirectoryName, "Book1.xlsx"),
               destFileName:=My.Computer.FileSystem.SpecialDirectories.Desktop & "\Book1.xlsx")
      Catch ex as Exception
         MessageBox.Show("Could not copy the file because someone has deleted the Book1.xlsx")
      End Try 
    End sub

  29. #29
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,319

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by Kram Kramer View Post
    Whenever the User runs the application one copy of Book1.xlsx file shows up in the Output Folder.
    NO! Are you incapable of reading? There is no output folder on the end user's computer. The "output folder" is where VS writes the output of the build process. If the user is running the application then you have already copied the contents of the output folder on your machine to the program folder on their machine, so your data file is already there. There's no more copying to be done. The data file is already there in the same folder as the executable file.
    Quote Originally Posted by Kram Kramer View Post
    I wish someone has no chance to delete Book1.xlsx file from Output Folder.
    Too bad. Just because you want something doesn't mean you can have it. People can delete files. Get over it. Write your code properly with that knowledge in mind.

    Of course, if you were to embed the file in your executable as a resource then that could never be deleted. That's already been suggested three times though, so if we're still having this conversation then either that isn't an acceptable solution or you've just ignored it, like you seem to have ignored so much else.

  30. #30
    PowerPoster ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    2,097

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Quote Originally Posted by Kram Kramer View Post
    The problem is the User or Someone else is able to delete Book1.xlsx file.

    I dont want the User or Someone else is able to delete Book1.xlsx file.

    I dont want the following code throws an exception.

    Code:
    Private Sub Button1_Click(sender As Object, e As RoutedEventArgs) Handles Button1.Click
      Try
          IO.File.Copy(sourceFileName:=IO.Path.Combine(New IO.FileInfo(Reflection.Assembly.GetExecutingAssembly.FullName).DirectoryName, "Book1.xlsx"),
               destFileName:=My.Computer.FileSystem.SpecialDirectories.Desktop & "\Book1.xlsx")
      Catch ex as Exception
         MessageBox.Show("Could not copy the file because someone has deleted the Book1.xlsx")
      End Try 
    End sub
    still didn't answer my question

    I give up
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  31. #31
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    32,505

    Re: [RESOLVED] Copy to Output Directory: Copy Always question

    Waaaaait....I know.... This is a VBF version of Candid Camera, right? Steve, is that you behind the keyboard?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width