Relative path to physical path - c#-4.0

<rant>
firstly, I've searched a lot and every single question / blog asks/tells about how to convert physical path to relative, never the other way around. If I've missed that question here, I am sorry.
<rant />
So, I have a directory structure very similar to this:
Root
|....Components
|....Classes
|....Utils
|....FileUtils
|....Assets //this is a folder
|....FileAccess.cs
So, in my FileAccess.cs I just want to read the content of a text file and display it on a page.
in my webpage.aspx.cs I am calling the getFileContent() which is in utils.
so the relative path from FileAccess.cs is Assets\spec.txt
So, how on earth can I access that with code?
this is what I am trying / tried:
//function getFileContent() content..
private const string QuestionnairePath = #"Assets\";
return Server.MapPath(QuestionnairePath + "spec.html");
it ALWAYS throws file not found exception and upon debugging it's not selecting the right folder.
I have even tried this:
private const string QuestionnairePath = #"~Utils\FileUtils\Assets\";
that doesn't work either.
This must be very easy. Just can't figure it out, for the life of me. I hate being a newbie sometimes.
Help please,
Thanks.
ps: Ideally, I would just want to use relative path: Assets\ - wonder if that is possible.

Related

Search file in a folder from Onedrive in Azure logic app

I'm having an issue using the OneDrive for Business - List files in folder action.
I'm setting the path of the action to be a parameter received from a previous step via http request.
The value of the path is for example - /Clients/ER/EDI/ERGL/Source
When I hard code the path by selecting it in the OneDrive action, its value at runtime is
"datasets/default/folders/01RODCPVEAQQCC4IDDRBF3JHJW2GR43CXZ" and at design time it is set to
"path":
/datasets/default/folders/#{encodeURIComponent(encodeURIComponent('01RODCPVEAQQCC4IDDRBF3JHJW2GR43CXZ'))}
However, when I try and set the path via parameter, which at design time looks like this
"path":
/datasets/default/folders/#{encodeURIComponent(encodeURIComponent(triggerBody()?['Source']))}"
and is at run time - /datasets/default/folders/%252FClients%252FER%252FEDI%252FERGL%252FSource
it does not work. I'm obviously missing something here, with encoding the path parameter? Any suggestions?
Thanks,
Actually you get the true path, it's just in a encode format. You could find the example , the encodeUriComponent will return the URI-encoded string with escape characters.
So you could decode what you get with this expression:
decodeUriComponent(decodeUriComponent('%252FClients%252FER%252FEDI%252FERGL%252FSource'))
Then you will get the absolute path.
Hope this could help you, if you still have other questions, please let me know.

Get a top level from Path object of pathlib

I use pathlib to match all files recursively to filter the files based on their content. Then I would like to find what is the top level of the folder of this file. Assume the following. I have a file in the folder:
a/b/c/file.log
I do the search from the level a:
for f in path_data.glob("**/*"):
if something inside file f:
# I would like to get in what folder this file is, i.e. 'b'
I now that I can get all parents levels using:
f.parents would give me b/c
f.parent would give me c
f.name would give me file.log
But how could I get b?
Just to precise: the number of levels where the file is stored is not known.
UPD: I know I could do it with split, but I would like to know if there is a proper API to do that. I couldn't find it.
The question was asked a while ago, but didn't quite get the attention. Nevertheless, I still would publish the answer:
f.parts[0]

path.join does not work?

I want to read from a path and I wrote two different codes.The first code does not work but the second code works perfectly. I do not understand the differences. can someone explain to me what is going on? thanks.
the file is stored in /modules/config/
First Code:
var tmpModulePath = path.join('./modules/',"config/");
var moduleConfigInfo = require(tmpModulePath + "_test.js");
Second code:
var tmpModulePath = path.join('./modules/',"config/");
var moduleConfigInfo = require("./" + tmpModulePath + "_test.js");
from the first code, I do get this error: Can not find module ..._tset.csv
If you console.log the generated path you get this results:
First code block:
"modules/config/_test.js"
Second code block:
"./modules/config/_test.js"
In the second case, you have a relative path starting from your current directory (./). require will look for a modules folder starting from your current directory.
In the first case, the path is absolute, meaning that require will look for a modules folder starting from the root path of your filesystem.
I hope you understand the difference now.
What you really want to use in this case is path.resolve:
var tmpModulePath1 = path.resolve('./', 'modules/',"config/", 'test.js');
Check the answer to this question to understand the difference between .join and .resolve.

How to encode a PHP file with base64

:)
I have one ridiculously silly question and most of you would like to reffer me to Google right away, but that didn't helped me out within the first hour. I suppose I didn't knew how to look for. I'm having a PHP file and I'd like to have it in base64 yet I can't get it to work anyhow.
1) I encoded my PHP script to base64(and included the PHP tags). It'll look as following : JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ==
This kind of base64 won't execute so I added the PHP tags to it although the encoded file already had it. Still didn't worked out. Removed the tags from the base64 and tried again, but still didn't worked. Then I tried adding the PHP tags and inside of them added :
eval(gzinflate(base64_decode('base64 here')));
Still didn't worked out anyhow. Is anyone here kind enough to tell the kiddo how to run a base64 encoded PHP file properly?
Would be really appreaciated. :)
A simple code:
$source = "JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ==";
$code = base64_decode($source);
eval($code);
or even shorter:
eval(base64_decode("JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ=="));
Do you want to encrypt your code? If so, this is not the right way. Use a accelerator like this one or this one. They will crypt your codes and make them even faster!
If you are going to use base_64 to encode your php file then the encoded text need to seat in between the php tags including the base_64 tag.
Example:
If your code is:
JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ
Then your code should look like:
<?php eval("?>".base64_decode("JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ")); ?>
Basically your basic code will look like this:
<?php eval("?>".base64_decode("Code Goes here")); ?>
There are more simple tools that can give you this option
Check this out: PHP Encoder & Decoder with Domain Lock

Theme_image() returns nothing

I'm stuck on a roadblock with the simplest of things. In Drupal 6, I'm trying to take a user-entered path to an image and output that image to the page. Here's a bit of code:
$slogan_image = theme('image', $slogan_image_path);
dpm("\$slogan_image_path = '$slogan_image_path'");
dpm("\$slogan_image = '$slogan_image'");
The devel output reads:
$slogan_image_path = '/sites/default/files/images/Family.jpg'
$slogan_image = ''
There is an image at '/sites/default/files/images/Family.jpg'; if I browse to www.mysite.com/sites/default/files/images/Family.jpg, the image will be displayed.
What am I doing wrong? Thanks.
The problem was that my path began with a slash. Drupal paths don't have that initial slash. Drupal being open source, I could look refer to the Drupal 6 api docs and see the code for theme_image included this line:
$url = (url($path) == $path) ? $path : (base_path() . $path);
showed me that Drupal would prepend my path with the base_path(). Executing that code myself, in an Execute PHP page, allowed me to see that theme_image would wind up using //sites/default/files/images/Family.jpg as the $url, clearly an illegal value.
I thought I'd append this short explanation to my trivial problem to help rank beginners see how I debugged it.

Resources