what is absolute path in C++/WinRT - console

the error: WinRT originate error-0x80070057:'The specified path (msappx:\Local\C:\Windows\Web\Screen\img103.png) is not an absolute path, and relative paths are not allowed. '
when I used C++/WinRT,the function call is
winrt::Windows::Foundation::IAsyncOperationwinrt::Windows::Storage::StorageFile temp = StorageFile::GetFileFromPathAsync(hFilname);
what can I do?

For StorageFile.GetFileFromPathAsync() method, you don't have permission to access the specified file, please see here.
My suggestion is that you could store the image file in Application install directory that app can access, then use the following code to access it.
StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;
string path= Path.Combine(folder.Path, #"Data\img1.png");
StorageFile.GetFileFromPathAsync(path);
Note that the Application install directory is ..ProjectPath\bin\x86\Debug\Appx

Related

How to get absolute path to "outputs" folder in Azure ML

In the documentation of Azure Machine Learning, under "Where to write files", it says
Otherwise, write files to the ./outputs and/or ./logs folder.
These are relative paths, i.e. relative to the folder where my script is run by the Azure ML framework. I was not able to find a function in the Azure ML SDK that would return the absolute path -- have I missed it or is there none? (Meaning that I should read the cwd at the beginning of my script and store it myself.)
For absolute path refer this code block:
processed_output_data = PipelineData("processed_data1",datastore=def_blob_store)
print("PipelineData object created")
train_data = PythonScriptStep(
script_name="sample.py",
arguments=["--input_data", blob_input_data, "--output_train", processed_output_data],
inputs=[blob_input_data],
outputs=[processed_output_data],
compute_target=aml_compute,
source_directory=source_directory,
runconfig=run_config
)
for information refer this Github link.

Why does `getResourceAsStream` sometimes load a resource even when there is a typo in the resource path?

I have a Jar (we'll call it a.jar) with a resource in it at path foo/bar.txt and a function as follows:
object FooBarLoader {
fun loadFooBarText() = javaClass.getResourceAsStream("foo//bar.txt")
?.bufferedReader()
?.readLines()
?.joinToString("\n")
}
When I test the function in a unit test (JUnit 4, running with Gradle 6), it loads the text from the resource file despite the obvious typo (the // in the middle of the resource path).
I also have a CLI application (in b.jar) that has a dependency on a.jar. When the CLI application calls loadFooBarText(), it got a null result due to the resource not being found. This was fixed by fixing the typo (// -> /) in the function in a.jar. No other changes were needed to fix it.
So, my question is why did the wrong path work in one situation (unit tests of a.jar) and not the other (call from b.jar)?
How do you run the unit test with a.jar ? Just run it in your IDE or use command java -jar a.jar ?
If you ran it just in IDE,I think difference is the search path between local files and zip files .
Your first application searches the file in your target directory and the second application searches it in the jar which is a compressed file.
When searching files in local path, command will be changed to right one by system.
The two commands below are the same in both Windows/Linux.
cd work//abc/ddd
cd work/abc/ddd
But when searching files in a jar file which is actually compressed zip file, path should be a restrict written or else the program will find nothing.

absolute File path to relative file path

I have a class library project (D:/projectName/SampleClassPrj) and a console application project D:/projectName/ConsolePrj.
In class library project, a json file test.json and a class sample.cs (read and deserialise json) both present.
d:/projectName/SampleClassPrj/test.json
d:/projectName/SampleClassPrj/sample.cs
This works with absolute path like,
d:/projectName/SampleClassPrj/test.json
but not working with relative path.
with relative path, by using file not found error as it is trying to find the file in the console (running) application assembly folder.
D:/projectName/ConsolePrj/bin/test.json
please help to find the solution
first, check json file property "copy if newer".
then, use Appdomain.CurrentDomain.BaseDirectory
string result = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConnectionString.txt"));
var path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location.Substring(0, Assembly.GetEntryAssembly().Location.IndexOf("bin\")));
StreamReader r = new StreamReader(Path.Combine(path, "sample.json"))
for .NET core 3.1
This worked for me

Can't Delete file with File.Delete(path)

I'm unable to delete file with this command ..
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path
Im getting the above error ..
However Im able to download file with the very same path..
Additional Details: I've have File path saved in the DataBase..
and files are in the ~\Upload\ folder ..
Path like this "~\Upload\ folder" are virtual paths. You need to convert them to physical path to delete them.
If you are in web context then use the following code to get physical path and then delete them.
var physicalPath = HttpContext.Current.Server.MapPath("~/Upload/folder/file.html"); //to get the physical path
File.Delete(physicalPath);
Ensure that you are escaping any backslashes/forward, and just generally check that your path is complete with no small errors.
Failing that make sure your program has the correct privileges to delete the file.
Sorry I can't be more specific but you have not shown your code.

How to get the uploaded file path?

I am using input tag type="file" to browse the file in asp.net.
I browsed the file "Linq2sql.zip" from the location "c\Desktop\Karthik\Linq2sql.zip".
i can get the file name and path using
HttpPostedFileBase file;
var filePath = Path.GetFullPath(file.FileName);
But File path is like = C:\\Program Files (x86)\\Common Files\\Microsoft Shared\\DevServer\\10.0\\Linq2sql.zip
i have to get the original file path c\\Desktop\\Karthik\\Linq2sql.zip. How can i get?
You can not get the original path of the file on the client system; that information is not sent by the client.
The reason you get what you do with GetFullPath is because that forces a resolution with the simple file name alone with the current directory of the asp.net process. That info is utterly meaningless - and in fact incorrect - in this case.

Resources