c# - Best way to for handling paths -


in project, have 2-3 classes having paths local filesystem folders. below:

class 1:

 private static string upload_root = "~/uploads/";  private static string images_folder = "images"; 

class 2:

 private static string upload_root = "~/uploads/";  private static string psd_folder = "generated photoshop psds"; 

so, can see, upload_root repeating wherever need it. want keep these paths in single file. how should that?

possible solution can see put these files in static class , use below:

public static class pathsettings {    public static string upload_root = "~/uploads/";    public static string images_folder = "images";    public static string psd_folder = "generated photoshop psds";  } 

then using class below:

file.saveas(pathsettings.upload_root + filename); 

how should store then? using static class best solution? used in cmses?

the static class constants valid. main downside approach application need recompiled in event directory moved.

so, consider moving constants out application's web.config file. when need figure out value, pull out of web.config file illustrated in answer:

declare string in web.config file

(not sure if ~ allowed in web.config string. easy enough tack on after reading it.)

edit:

cmss use configuration files store paths such these, , common static library used pull path information. there ui administrator change paths, in turn edits file full of path info.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -