How to obtain file name from URI object in C++/WinRT

232 Views Asked by At

I am working on a C++WinRT UWP app. I have URI object which contains the file path for downloading file over the internet. I want to extract only the file name with extension from this URI object. I want to create a local file with this name. Is there a library method to do this? Appreciate the help. Thanks

1

There are 1 best solutions below

0
IInspectable On

This question is rooted in a fundamental misunderstanding. File names are meaningful only in context of a file system. The HTTP protocol (which you are presumably using) does not model a file system.

URIs

identify a logical or physical resource used by web technologies. URIs may be used to identify anything, including real-world objects, such as people and places, concepts, or information resources such as web pages and books.

Consequently, the Uri type does not limit itself to identifying files, and as such does not provide properties or methods to extract a file name (which may or may not exist after all).

If you are lucky the server you are communicating with provides a filename parameter in the Content-Disposition response header which you can use as a file name for local storage.

If not you will have to invent a file name of your choosing.