How to deal with Absolute and relative paths?

Hi. I am trying to download an excel file and open it using excel application scope. For this I am reading the path from ‘save as’ window when I am downloading the file and using the same path for opening it again in excel application scope. The problem I am facing here is: when I copy the path from save as it is something like ‘Downloads’. Then I add ‘\filename.xlsx’ to the path. I am trying to use this whole ‘Downloads\filename.xlsx’ when opening with excel application scope. The problem here is excel scope is considering this as relative path throwing up an error ’ cannot find file at C:…\project folder\ downloads\filename.xlsx …’ so the excel scope is automatically considering this as relative path. Can anyone suggest me how to deal with this? I also tried to type a fixed path in save as window, but I am unable to type into the address bar. Any help is appreciated.
Thanks
Yeswanth.

1 Like

please replace “/” with "\"

sorry that was a typo in the question edited now

can you please share the exception screen for better understanding?

this is my project file

my file name is challenge.xlsx. which is printed on the above line. but when I pass it to excel application scope, some random numbers are replacing my file name. please have a look at my .xaml file : https://drive.google.com/file/d/1PdlvW4SkNwlHKKeFRzpMm8BS4VAov7-Q/view?usp=sharing

Hi @Yeshwanth_Thiyari,

Can you tell me the full path of the Challenge.xlsx file?

Regards,
Arivu

It is in Downloads folder(C:\users\yeswanth\Downloads), but excel scope is trying to find the Downloads folder inside the project folder. I could prefix with the exact path, but I want it to be robust. I want to capture the path while downloading and use it when opening.
Thanks

If it is always downloads, you could do:

%userprofile%\downloads

This would be more robust than hardcoding completely if it is used on multiple user profiles, but it still makes the downloads folder the final output location

1 Like

“C:\users\yeswanth\Downloads\Challenge.xlsx”

Regards,
Arivu

yes I could do that if I always save in downloads. But in this case the file is in downloads, sometimes it might be in some other folder. That is why I am trying to read the path while downloading.
Thanks,
Yeswanth.

So you’re not sure where the files are downloaded to? The best way to do this is fix the process so you know where the files are downloaded :slight_smile: . Then you can save the full path as a string when downloading, and pass that same string later when you need to open the file. Just an FYI that you can type in full paths in the filename box, you don’t need to only type the file name.

E.g. type “C:\users\yeswanth\Downloads\Challenge.xlsx” in the filename box instead of navigating to the downloads folder and only typing “Challenge.xlsx”

If you want to save it in a random location it will be much harder to figure out because using the save as box doesn’t always display all the info needed. You’d likely have to look through various directories for file.fileinfo properties that match what you’re looking for…much harder, longer to run, and more prone to error

Hi @Yeshwanth_Thiyari,

Try to use below code

Environment.GetEnvironmentVariable("userprofile")+"\Downloads\"+yourDownloadedfileName.xlsx

So As per you screenshot and your xaml file use below code in the excel Application scope

Environment.GetEnvironmentVariable("userprofile")+"\"+F_Path

Regards,
Arivu

1 Like

Thank you Dave. I got your point. I also tried to create a folder for the downloads and supplying it to save as window while downloading. But I cannot type into the address bar of the save into field also as it is not a regular text field. Do you have any suggestion for typing into the address bar of save into window?
Thanks,
Yeswanth.

Thank you for the code. But the problem is I don’t always save into downloads as I mentioned.

I’ll attach an example. You don’t type into the address bar, you instead type in the full absolute file path in the filename portion

EDIT: here’s the example file. It just goes to google.com and saves it as a .jpg , but you should be able to do the same with any file type
SaveFileExample.xaml (10.6 KB)

Problem with your workflow is you captured Downloads from address bar and you passed the same path to your excel application scope so it will take the relative path i.e, from your project folder+filepath you provided where the folder downloads doesn’t exists in your project folder. this was the reason for abnormal behaviour.

Thank you Dave. I just tried typing into the file name and it worked perfect. Thank you all for your solutions.
Yeswanth.

1 Like

Yes I understood that.And I was trying to solve the same.
Thanks,
Yeswanth.