none
how to set the current directory's path

    Question

  • I need to know how to set my current directory to a known location on the server.  I've asked this question in several threads but not gotten a workable answer.  I need to place a directory in a location on the server that other projects may access it.  I have thus far chosen the root as a convenient location.   Everything is fine in my local server environment but when I deploy this solution I get a failure saying that I cannot access "c:\sdata".  Well, "sdata" is the directory I am trying to access and the c:\ is probably where the original directory came from but what can I do to avoid this problem.  I just got a response on one of my threads that it is probably just a protection problem on the server side.   I'd love for that to be the answer, but I'm afraid its not that simple.  I changed the attribute of the file on my location to be "not read only" and redeployed it to no avail.  So is there a different method for changing that I am not aware of?  I just find it hard to believe that it can   be that complicated!

    Maybe I should place the directory within one of the solution's folders, say "Bin", so that it will inherit the proper rights upon deployment.  I would sure love some help on this.


    eps123

    Thursday, June 2, 2016 4:03 PM

Answers

  • Thank you Konrad, the last response you gave me is definitely an answer, although not to my original question.  I installed the extensions you gave me and the setup1 options became visible to me.  I now was trying to reconnect with Moonlight's instructions to add a setup project. The screenshot below indicates where I ran into a roadblock.  Should I be replying to him and/or you to clarify what I must do next?

    eps123

    • Marked as answer by eps123 Tuesday, June 14, 2016 6:30 PM
    Tuesday, June 14, 2016 6:29 PM
  • I've done as you suggested.  Hope for a response from anyone.

    eps123

    • Marked as answer by eps123 Friday, June 17, 2016 8:11 PM
    Friday, June 17, 2016 8:10 PM

All replies

  • Hi,

    maybe in one of the other threads you gave more details already, but what do you want to do with that directory? And what kind of project do you develop?

    In general, when your application needs multiple files to run and must not change these, the recommend way for a desktop application is to put everything inside the install directory. To get everything up and running on other systems, the common way is to provide an installer (MSI) which is taking care of everything. (We are using wix to create these installers).

    Desktop applications that need to write data will store this inside a directory where the user has write access. Documents that the user should be aware of should be defaulted inside the My Documents folder of the user. Data which files should not be visible for the user should be stored inside the ApplicationData folder of the user.

    To get hold of the directory, you can use the Environment.SpecialFolder enumeration.

    With kind regards,

    Konrad

    • Marked as answer by eps123 Thursday, June 2, 2016 8:41 PM
    • Unmarked as answer by eps123 Wednesday, June 8, 2016 8:42 PM
    Thursday, June 2, 2016 6:32 PM
    Moderator
  • Thank you for the response even before I have had a chance to try using your environment... goodie.  To answer your questions, the directory is nothing but an app directory to consolidate necessary information files and allow for reports to be created  and viewed.  I would like to follow up with you after I've tried your enumeration, successful or not, but for now could you give me a reference for a source of routines such as what you gave me (Env...SpecialFolder)?


    eps123

    Thursday, June 2, 2016 8:51 PM
  • Hi,

    the Environment.SpecialFolder enumeration is documented here:
    https://msdn.microsoft.com/en-us/library/system.environment.specialfolder(v=vs.110).aspx

    The LocalApplicationData directory could be used to create files that your application needs write access to and that the user should not see. If the data should be available on all systems of a roaming user, you should use ApplicationData.

    For real documents, that the user should see and that belong to something that is sometimes called "library of the user", the Myxxxx elements are available. MyDocuments for documents. So if you create a report then the user might want to have it there. MyMusic, MyPictures, ... are also available. But the user should be aware of these files, you should always ask the user where to save it and which filename should be used when you use these directories! The user is the owner of that area and he should decide what to safe or not safe and which names should be used.

    And there is one special case: temporary files. If you want to write temporary files (e.g. during report creation), then you could use Path.GetTempFileName to get a temporary file (which you should clean up at the end again).

    You get the path of an element of the Environment.SpecialFolder enumeration through a call of

    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)

    And check the directory which you want to use. Some directories have a specific structure e.g. Vendor\Software that you might want to use. The Vendor directory alone could be used if multiple applications of you should access the same files.

    And one last point: Thank you for marking my first reply as answer. It is great and really wanted to have replies marked as answer that was useful to answer your questions. But it is also seen as some kind of "closing" the thread. A lot of people who help others do not read answered threads. So I would recommend to even unmark my first reply again in case that I was unable to fully answer your question now. If you need to get more clarification inside a thread but want to mark a reply as useful, then you could upvote it.

    With kind regards,

    Konrad

    Friday, June 3, 2016 5:44 AM
    Moderator
  • Thank you again Konrad.

    I have marked the previous response as "unanswered as you suggested.  The "environment.getfolder...." solution you provided me was attempted by me, but not knowing exactly what to do with it or how to employ it, I resorted to reading the documentation.  This left me more confused than ever so I copied some sample that was provided there and was met with failure when that would not compile successfully.  At this point I gave up on that and I do not know where to go.  After programming for over 50 years I feel stupid in not being able to accomplish what seemed like a trivial task when I started.  I have created a simple minded solution that mirrors my situation and pasting in the solution explorer view.  I am hopeful that you can tell me that we are pursuing the same goal, or hopefully, that there is a simpler way to go about it.  

    The bin folder is an additional folder that I added to the solution with the intent of placing my own directory and its files in that folder.  If I can deploy that with my solution successfully, then my problem is solved.  I do not even wish to worry about how my other independent projects will access this same folder (which they need to).

    The code I am replacing in my code-behind file is "chdir( x)".   x is somehow defined to be bin as shown in my solution.  Please get back back to me and tell me I am not asking for too much or that I already have the approved answer.


    eps123

    Sunday, June 5, 2016 7:43 PM
  • Hi eps123,

    >>The bin folder is an additional folder that I added to the solution with the intent of placing my own directory and its files in that folder.  If I can deploy that with my solution successfully, then my problem is solved. 

    Firstly, thanks for sharing your solution here. But to make sure that whether there are other better solution for this issue, maybe you could provide us more information about this issue.

    >>Everything is fine in my local server environment but when I deploy this solution I get a failure saying that I cannot access "c:\sdata".  Well, "sdata" is the directory I am trying to access and the c:\ is probably where the original directory came from but what can I do to avoid this problem. 

    So you mean that your current project has some referenced files which are saved out of the current solution folder, am I right? Do you create the setup project using the click-once since I see that it was the WinForms app?

    If it is related to the click-once, maybe you could think about using the .xxproj file like this sample:

    http://stackoverflow.com/questions/590227/why-doesnt-clickonce-in-visual-studio-deploy-content-files-from-dependent-assem

    If I have misunderstood this issue, please feel free to let me know.

    Best Regards,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.



    Thursday, June 9, 2016 7:55 AM
    Moderator
  • I think that I am being misunderstood.  The applications that I am building are intended to run on a host server.  All three projects that I have designed operate successfully on my own computer using a local browser.   There is some database and sql stuff employed in these projects and all is well with that end of the requirements.  There is a requirement for  the data which have been input by clients for analysis.  I have written the code for the analyses using standard VB and File IO logic.  There is one key file that is used for the analysis and I have placed it inside a folder in my local environment.  There are two other files in the folder that are routinely used and updated by the application, and these too are placed in my folder.  Finally, the analysis produces reports routinely in the course of running and these are also written into my folder which I have named SDATA.  

    In my local environment I chose to place the folder in the root of the computer.  In any of my applications, in the loading of the application, I execute the statement:    chdir("/SDATA") or some alternate variation to set the currently assumed directory to my folder SDATA.  Everything works great until  I deploy the software  and it fails on that statement for the reason I now understand.  [We must not use a fixed location on the server, only a relative].  The "/SDATA" is translated by the server as "C:/SDATA", an absolute no no.  To my way of thinking there should be some way of addressing the root of the server.  There has to be an easy solution which I am trying to discover.  In my many attempts to solve this problem I thought that moving my folder to the bin folder of my solution or the app_data folder, might allow the deployment but I am faced with the same problem of how to set my directory.  I will be very grateful for your continued support.                                                     Eps123


    eps123

    Thursday, June 9, 2016 7:03 PM
  • Hi eps123,
    >>Everything is fine in my local server environment but when I deploy this solution I get a failure saying that I cannot access "c:\sdata". 
    It seems that the relative path isn't suitable with the custom installer class , the system recognize the path to 'C: /...'.
    If you want to get the installation path, you could select the Install action and set the CustomActionData property to:

    /targetdir="[TARGETDIR]\"

    Access the path:

    [RunInstaller(true)]
    public partial class CustomInstaller : System.Configuration.Install.Installer
    {
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);
            string path = this.Context.Parameters["targetdir"]; 
            // Do something with path.
            // path +("/SDATA") 
        } 
    }

    Regards,
    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Friday, June 10, 2016 7:10 AM
  • Hi,

    I am exuberant that I have found someone who seems to understand my problem.  You have apparently given me a complete answer but I do not understand how or where to incorporate these pieces into my code.  For example where do I set the property /targetdir?  Where does the code you provided get inserted, in my aspx code? You can see by these questions that I am new to this despite fifty years of programming in many other suurroundings.

    I will greatly appreciate your further elaboration.

     


    eps123

    Friday, June 10, 2016 3:38 PM
  • Hi eps123,

    >> For example where do I set the property /targetdir?

    You could follow these steps:

    1. Right-Click on setup project, and choose the view.

    2. Choose the 'Custom Actions', then you will see the custom actions menu.

    3. Right-Click on 'Install' Folder and chose 'Add Custom Action'.

    4. Add the custom action of the primary output.

    4. Right-Click on the custom action file which you have added, choose the properties window, then you will find the 'CustomActionData' property(I have inputted the property).

    >> Where does the code you provided get inserted, in my aspx code?

    Add a new Installer class to the target project, then put these code into the installer class.

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Monday, June 13, 2016 7:21 AM
  • Thank you for a detailed response, but I am lost on step 1.  (Right-Click on setup project, and choose the view. )

    I guess I do not understand where setup project is accessed.  I am using Visual Studio 2013.  I tried to rightclick project and got the screenshot as shown.      


    eps123

    Monday, June 13, 2016 3:49 PM
  • Hi,

    >>but I am lost on step 1.  (Right-Click on setup project, and choose the view. )

    Right-Click on your setup project, if you not have setup project ,you should add it first.

    Steps: Your Solution -> Right-Click, 'Add New Project', choose the setup project.

    How to: Create or Add a Setup Project

    Creating an MSI Package Using a Visual Studio Setup Project

    Regards,

    Moonlight


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    Tuesday, June 14, 2016 8:20 AM
  • Hi Jack,

    Sorry for the late answer but I am off chasing what seems to be an answer to my problem. In your last message you asked a couple of questions I could not fathom. I do not know what the click-once is and I do not understand what you mean by the setup project.  It should not matter what files are in the directory I am trying to access since I am using the directory as a repository for reports I created as well as some data files I use for the applications I run.  I will now hope for an answer from my other respondent that will answer my questions for good on this issue.


    eps123

    Tuesday, June 14, 2016 12:19 PM
  • Thanks but as you can see in the screenshot below, I do not get the Visual Studio Setup option when I try  to add the project.  Might the answer be that I must do that first at the beginning? 


    eps123

    Tuesday, June 14, 2016 1:24 PM
  • Hi,

    the Visual Studio Setup Project is no longer part of the main setup of Visual Studio. (It was removed with Visual Studio 2012).

    It is available through the Visual Studio Gallery and must be installed manualy.

    To install it, you simply go to Tools -> Extensions and Updates.
    Click on "Online" and then use the search box to look for "Installer Projects". That way you should find the Microsoft Visual Studio 2015 Installer Projects.

    The page to the setup projects is:
    https://visualstudiogallery.msdn.microsoft.com/f1cc3f3e-c300-40a7-8797-c509fb8933b9

    With kind regards,

    Konrad

    Tuesday, June 14, 2016 1:39 PM
    Moderator
  • Thank you Konrad, the last response you gave me is definitely an answer, although not to my original question.  I installed the extensions you gave me and the setup1 options became visible to me.  I now was trying to reconnect with Moonlight's instructions to add a setup project. The screenshot below indicates where I ran into a roadblock.  Should I be replying to him and/or you to clarify what I must do next?

    eps123

    • Marked as answer by eps123 Tuesday, June 14, 2016 6:30 PM
    Tuesday, June 14, 2016 6:29 PM
  • Moonlight.

    You have lost me.  I have now added a setup project to a simple solution that demonstrates my problem.  I guess my problem is accessing the directory that is on my c drive in my local visual studio environment.  I've followed your instructions up to the point where I have the screen shot shown below.  I do not know how to proceed.  Are we still on the same wavelength?

    THANK YOU


    eps123

    Thursday, June 16, 2016 5:22 PM
  • Hi eps123,

    Actually this forum is to discuss the VS IDE, I discussed this issue with Moonlight Sheng before, and he provided you some suggestions, actually this issue would be related to the ClickOnce and Setup & Deployment Projects which also has his own supported forum here:

    https://social.msdn.microsoft.com/Forums/windows/en-US/home?forum=winformssetup

    To help you resolve this issue, and not view so many previous replies, would you please open a new case in above forum? Moonlight Sheng will provide you the detailed steps about how to resolve this issue there. Of course, if you open a new case in above forum, you could share a link here, so other members also get useful information or the correct forum during they meet the similar issue as yours.

    Thank you for your support and co-operation.

    Sincerely,

    Jack


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, June 17, 2016 9:15 AM
    Moderator
  • I've done as you suggested.  Hope for a response from anyone.

    eps123

    • Marked as answer by eps123 Friday, June 17, 2016 8:11 PM
    Friday, June 17, 2016 8:10 PM