how to read a file from a different project?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







0















how to read a file from a different project?



I have a solution:



Solution1
-MyProject
-MyProject.Artifacts
----Message.XML
-MyProject.Tests


I am attempting to read the contents of Message.XML from MyProject.Tests.



How do I read the contents of Message.XML from MyProject.Tests?



Unfortunately, right now I'm doing something like this, but it's not very pretty:



        var currentDir = Directory.GetCurrentDirectory();
var parentDir = Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName;
var parentParentDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName).FullName;
var parentParentParentDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName).FullName).FullName;









share|improve this question























  • What kind of application is it? Web, Console or WPF ...? I think you can define the XML output folder yourself. Thus, you can refer to this: stackoverflow.com/questions/6041332/…

    – wannadream
    Nov 16 '18 at 20:12











  • its an azure function

    – l--''''''---------''''''''''''
    Nov 16 '18 at 20:46


















0















how to read a file from a different project?



I have a solution:



Solution1
-MyProject
-MyProject.Artifacts
----Message.XML
-MyProject.Tests


I am attempting to read the contents of Message.XML from MyProject.Tests.



How do I read the contents of Message.XML from MyProject.Tests?



Unfortunately, right now I'm doing something like this, but it's not very pretty:



        var currentDir = Directory.GetCurrentDirectory();
var parentDir = Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName;
var parentParentDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName).FullName;
var parentParentParentDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName).FullName).FullName;









share|improve this question























  • What kind of application is it? Web, Console or WPF ...? I think you can define the XML output folder yourself. Thus, you can refer to this: stackoverflow.com/questions/6041332/…

    – wannadream
    Nov 16 '18 at 20:12











  • its an azure function

    – l--''''''---------''''''''''''
    Nov 16 '18 at 20:46














0












0








0








how to read a file from a different project?



I have a solution:



Solution1
-MyProject
-MyProject.Artifacts
----Message.XML
-MyProject.Tests


I am attempting to read the contents of Message.XML from MyProject.Tests.



How do I read the contents of Message.XML from MyProject.Tests?



Unfortunately, right now I'm doing something like this, but it's not very pretty:



        var currentDir = Directory.GetCurrentDirectory();
var parentDir = Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName;
var parentParentDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName).FullName;
var parentParentParentDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName).FullName).FullName;









share|improve this question














how to read a file from a different project?



I have a solution:



Solution1
-MyProject
-MyProject.Artifacts
----Message.XML
-MyProject.Tests


I am attempting to read the contents of Message.XML from MyProject.Tests.



How do I read the contents of Message.XML from MyProject.Tests?



Unfortunately, right now I'm doing something like this, but it's not very pretty:



        var currentDir = Directory.GetCurrentDirectory();
var parentDir = Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName;
var parentParentDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName).FullName;
var parentParentParentDir = Directory.GetParent(Directory.GetParent(Directory.GetParent(Directory.GetParent(currentDir).FullName).FullName).FullName).FullName;






c# .net visual-studio visual-studio-2017






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 19:47









l--''''''---------''''''''''''l--''''''---------''''''''''''

11.4k238543885




11.4k238543885













  • What kind of application is it? Web, Console or WPF ...? I think you can define the XML output folder yourself. Thus, you can refer to this: stackoverflow.com/questions/6041332/…

    – wannadream
    Nov 16 '18 at 20:12











  • its an azure function

    – l--''''''---------''''''''''''
    Nov 16 '18 at 20:46



















  • What kind of application is it? Web, Console or WPF ...? I think you can define the XML output folder yourself. Thus, you can refer to this: stackoverflow.com/questions/6041332/…

    – wannadream
    Nov 16 '18 at 20:12











  • its an azure function

    – l--''''''---------''''''''''''
    Nov 16 '18 at 20:46

















What kind of application is it? Web, Console or WPF ...? I think you can define the XML output folder yourself. Thus, you can refer to this: stackoverflow.com/questions/6041332/…

– wannadream
Nov 16 '18 at 20:12





What kind of application is it? Web, Console or WPF ...? I think you can define the XML output folder yourself. Thus, you can refer to this: stackoverflow.com/questions/6041332/…

– wannadream
Nov 16 '18 at 20:12













its an azure function

– l--''''''---------''''''''''''
Nov 16 '18 at 20:46





its an azure function

– l--''''''---------''''''''''''
Nov 16 '18 at 20:46












2 Answers
2






active

oldest

votes


















0














You can store a path to the file in app settings of app.config / web.config using that read the file contents.



That way if you need to deploy your software in a different way you have the flexibility






share|improve this answer
























  • then i will need to maintain two sets of configuration files, one in my regular project and one in my tests project

    – l--''''''---------''''''''''''
    Nov 16 '18 at 19:53











  • Or us a config transform so when you run test you get set of values and run production you get a different set

    – thepolishboy
    Nov 16 '18 at 19:54





















-1














If your path is fixed, you can write the path like "c:projectssolution ... Message.xml"



If you want a relative path, the simplest way is this:



var DI = new DirectoryInfo("..\..\..\..\Your Folder\Message.XML");


This path is started from CurrentDirectory and goes four folders up and the one folder down and finds the file.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344434%2fhow-to-read-a-file-from-a-different-project%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    You can store a path to the file in app settings of app.config / web.config using that read the file contents.



    That way if you need to deploy your software in a different way you have the flexibility






    share|improve this answer
























    • then i will need to maintain two sets of configuration files, one in my regular project and one in my tests project

      – l--''''''---------''''''''''''
      Nov 16 '18 at 19:53











    • Or us a config transform so when you run test you get set of values and run production you get a different set

      – thepolishboy
      Nov 16 '18 at 19:54


















    0














    You can store a path to the file in app settings of app.config / web.config using that read the file contents.



    That way if you need to deploy your software in a different way you have the flexibility






    share|improve this answer
























    • then i will need to maintain two sets of configuration files, one in my regular project and one in my tests project

      – l--''''''---------''''''''''''
      Nov 16 '18 at 19:53











    • Or us a config transform so when you run test you get set of values and run production you get a different set

      – thepolishboy
      Nov 16 '18 at 19:54
















    0












    0








    0







    You can store a path to the file in app settings of app.config / web.config using that read the file contents.



    That way if you need to deploy your software in a different way you have the flexibility






    share|improve this answer













    You can store a path to the file in app settings of app.config / web.config using that read the file contents.



    That way if you need to deploy your software in a different way you have the flexibility







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 16 '18 at 19:53









    thepolishboythepolishboy

    246




    246













    • then i will need to maintain two sets of configuration files, one in my regular project and one in my tests project

      – l--''''''---------''''''''''''
      Nov 16 '18 at 19:53











    • Or us a config transform so when you run test you get set of values and run production you get a different set

      – thepolishboy
      Nov 16 '18 at 19:54





















    • then i will need to maintain two sets of configuration files, one in my regular project and one in my tests project

      – l--''''''---------''''''''''''
      Nov 16 '18 at 19:53











    • Or us a config transform so when you run test you get set of values and run production you get a different set

      – thepolishboy
      Nov 16 '18 at 19:54



















    then i will need to maintain two sets of configuration files, one in my regular project and one in my tests project

    – l--''''''---------''''''''''''
    Nov 16 '18 at 19:53





    then i will need to maintain two sets of configuration files, one in my regular project and one in my tests project

    – l--''''''---------''''''''''''
    Nov 16 '18 at 19:53













    Or us a config transform so when you run test you get set of values and run production you get a different set

    – thepolishboy
    Nov 16 '18 at 19:54







    Or us a config transform so when you run test you get set of values and run production you get a different set

    – thepolishboy
    Nov 16 '18 at 19:54















    -1














    If your path is fixed, you can write the path like "c:projectssolution ... Message.xml"



    If you want a relative path, the simplest way is this:



    var DI = new DirectoryInfo("..\..\..\..\Your Folder\Message.XML");


    This path is started from CurrentDirectory and goes four folders up and the one folder down and finds the file.






    share|improve this answer




























      -1














      If your path is fixed, you can write the path like "c:projectssolution ... Message.xml"



      If you want a relative path, the simplest way is this:



      var DI = new DirectoryInfo("..\..\..\..\Your Folder\Message.XML");


      This path is started from CurrentDirectory and goes four folders up and the one folder down and finds the file.






      share|improve this answer


























        -1












        -1








        -1







        If your path is fixed, you can write the path like "c:projectssolution ... Message.xml"



        If you want a relative path, the simplest way is this:



        var DI = new DirectoryInfo("..\..\..\..\Your Folder\Message.XML");


        This path is started from CurrentDirectory and goes four folders up and the one folder down and finds the file.






        share|improve this answer













        If your path is fixed, you can write the path like "c:projectssolution ... Message.xml"



        If you want a relative path, the simplest way is this:



        var DI = new DirectoryInfo("..\..\..\..\Your Folder\Message.XML");


        This path is started from CurrentDirectory and goes four folders up and the one folder down and finds the file.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 20:10









        MSLMSL

        5361918




        5361918






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53344434%2fhow-to-read-a-file-from-a-different-project%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Xamarin.iOS Cant Deploy on Iphone

            Glorious Revolution

            Dulmage-Mendelsohn matrix decomposition in Python