Developer forum

Forum » Development » Get path for Files directory

Get path for Files directory

Jonas Mersholm
Reply

Lets say i would like to load an XML file from razor using xDocument. How would i go about getting the destination/path to the files directory using c# ofc.

Everything i tried, is returning the /Appliaction(8.x.x) folder ( Getting the root path )

Is there a DW function i am missing?

 

best regards.

Jonas


Replies

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer

Hi Jonas,

You should be able to use something like System.Web.HttpContext.Current.Server.MapPath("~/Files") to get the physical path.

Hope this helps,

Imar

Votes for this answer: 1
 
Jonas Mersholm
Reply

Thank you Imar, that worked!

Last question, if you got the time. I am trying to define a Generic Dictionary in razor, but it seems, that due to dynamicweb's parser, the type definitions are being treated as html object/attributes.

 

var keyValues = new Dictionary<string, string>();

returns this nasty bugger:

Line 3: Syntax error, '>' expected
Line 3: Invalid expression term ')'
Line 3: ) expected

Probably due to the following, found a little later in the code

var keyValues = new Dictionary<string, string="">();

Notice how the <string, string> is being treated as a html object.

How to overcome this, so i can define my Dictionary in the razor view?

 
Jonas Mersholm
Reply

Thank you Imar, that worked!

Last question, if you got the time. I am trying to define a Generic Dictionary in razor, but it seems, that due to dynamicweb's parser, the type definitions are being treated as html object/attributes.

 

var keyValues = new Dictionary<string, string>();

returns this nasty bugger:

Line 3: Syntax error, '>' expected
Line 3: Invalid expression term ')'
Line 3: ) expected

Probably due to the following, found a little later in the code

var keyValues = new Dictionary<string, string="">();

Notice how the <string, string> is being treated as a html object.

How to overcome this, so i can define my Dictionary in the razor view?

 
Mikkel Ricky
Reply

Dynamicweb uses Html Agility Pack (HAP) for parsing layout templates and HAP gets confused by some Razor constructs.

Try adding spaces inside <>:

var keyValues = new Dictionary< string, string >();

Best regards,
Mikkel

 
 
Jonas Mersholm
Reply

Thank you Imar, that worked!

Last question, if you got the time. I am trying to define a Generic Dictionary in razor, but it seems, that due to dynamicweb's parser, the type definitions are being treated as html object/attributes.

 

var keyValues = new Dictionary<string, string>();

returns this nasty bugger:

Line 3: Syntax error, '>' expected
Line 3: Invalid expression term ')'
Line 3: ) expected

Probably due to the following, found a little later in the code

var keyValues = new Dictionary<string, string="">();

Notice how the <string, string> is being treated as a html object.

How to overcome this, so i can define my Dictionary in the razor view?

 
Jonas Mersholm
Reply

thank you Mikkel,

I just realized, that even though i define a razor functions block in my master template, i cannot call the functions from within other templates ( ex. news paragraphs ), even though i defined it as a public static. IS there any way i can define a global function without having to do custom modifications and compiling.

 

best regards.

Jonas

 
Mikkel Ricky
Reply

Each template is compiled separately and cannot use functions defined in other templates. You can put your functions into a file that you include in the templates where they are needed. See https://github.com/dynamicweb/itembasedmodules/blob/master/Files/Templates/Designs/itembasedmodules/ItemPublisher/List/Blog_Post_List.cshtml#L1-L2 for an example.

Best regards,
Mikkel

 

 
Jonas Mersholm
Reply

Great knowledge, but how would i get the current websites "Lang" variable, when all i see in EX. a news list, with a var-dump is 

News:RSS: 
News:FusionGoogle: 
News:WindowsLive: 
News:Search: 
News:Paging.Back: 
News:Paging.Forward: 
News:Paging.List:

Man, this Razor is smart, but aint easy to figure out the var names :)

 
Mikkel Ricky
Reply

You don't need var names. Just use the Area (website):

@Pageview.Area.get_Value("AreaCulture")

To get a list of keys, you can use something like 

<pre>
@foreach (var key in Pageview.Area.Values.Keys) {
    @: @key: @Pageview.Area.Values[key]
}
</pre>

Note that the string value passed to Area.get_Value is case-insensitive, i.e. Area.get_Value("AreaCulture") is the same as Area.get_Value("areaculture").

Best regards,
Mikkel

 

You must be logged in to post in the forum