How can I detect the "Downloads" folder in Xamarin forms? And do I need specific rights?
I cannot find a matching variable on this in GetFolderPath() nor FileSystemHelper.
Thx
In android, from external files, we can get Downloads folder by following code:
string path1 = Path.Combine(Android.OS.Environment.ExternalStorageDirectory.AbsolutePath, Android.OS.Environment.DirectoryDownloads);
The path like /storage/emulated/0/Download/
In ios, use this directory to store user documents and application data files.
var documents = Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments);
If you want to add or modify file in Download folder, you need request permissions in Android platform.
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
There is one thread that you can take a look:
How to open PDF file in xamarin forms
Related
I have an asp.net web api project using token based authentication. my app uploaded and retrieve images and I keep file path in table_myfiles along with the uploaded user ID.
I would like the user to access only the files he have uploaded, which I can identify from the table.
How to protect my resources to restrict access to only to the user based on table_myfile ? And not to anyone without logging in or direct link / path ?
I have been searching for any possible solution for a week now , I think I should implement a middleware to manage access. But I couldn’t find any resources on how to implement the same.
Currently my api shows all resources just by directly accessing the file path/link.
The simple apporach is to remove the vitural folder, or that folders from the web site folders. That way, no simple URL exists for any of the files.
So, for a user to get/see/use/download a file? You present say a listview or some kind of grid (or repeater) that displays and lists out the files.
Then, when they want to download or view a file?
You use response.write and stream the file down to the client side.
Remember, on the server, code behind uses 100% clean and correct windows file paths. For any web based URL, then that folder must be in a valid path of the web site. When they type in a valid URL, it eventually gets translated to that given folder in the site (or a external folder provided when you create a mapped "virtual" folder in IIS. However, if you don't provide that virtual folder, or the folder is NOT in the web site file/folder sets, then no valid URL's exist. However, that folder can be directly used and hit with code behind - any valid server path/folder name is allowed in code behind.
Because when streaming the file, you need path name, file name, AND ALSO the "mine" type. Thankfully, .net 4.5 or later has this ability.
so, from a database (table) I display the file names like this:
But, if you click on the preview image, that is a image button.
The code behind simply gets/grabs the file name from the database.
I then download (stream) the file to the browser side like this:
if (File.Exists(strInternalFullPath))
{
string strConType = MimeMapping.GetMimeMapping(strInternalFullPath);
binFile = File.ReadAllBytes(strInternalFullPath);
Response.ContentType = strConType;
Response.AppendHeader("Content-Disposition", "attachment; filename=" + Path.GetFileName(strWebUrl));
Response.BinaryWrite(binFile);
Response.End();
}
else
MyToast2(this, btnLink.ClientID.ToString, "File Not found", "We no longer have this file avaiable.");
so, this buttion behaves 100% like a link, but there are no existing URL's or path name that points to the files folder from a web based URL.
Remember:
Web based URLs - they auto map from the web site URL to a existing folder.
You can use server.MapPath("some url to file") to "translate" this to a internal file name.
Code based files:
In your .net code (code behind) ANY file name is a standard plane, jane file name that points to a file on the server.
so, once we have that file name from the database, you can steam the file as if the user clicked on a link. But you never have to expose the actual file name, or file path. And no such valid URL's exist on the web site, since you do NOT have that files folder in the web site folder hierarchy - but placed that folder outside of the web site.
As long as that folder is outside of the web folders, and as long as you don't setup a virtual folder that points to that folder outside the web folders?
Then code behind can STILL get/grab/see/use any file on the server. that code uses a full valid windows file name, - but the web site will have no mapping to such a folder - hence no valid URL's will exist or can be typed in.
I am trying to read a spreadsheet from a shared location folder. using
<cfparam name="xlfilepath" type="string" default="\\file02\OP\!FILE STRUCTURES and FORMS\Agreements\Tracker.xls" />
<cfspreadsheet action="read" src="#xlfilepath#" excludeHeaderRow="true" query="MsaDataSheet1" sheet="1" />
"OP" is the shared folder.
I got "java.io.FileNotFoundException:".Then I try to display the directory listing using cfdirectory tag.
<cfdirectory action="list" directory="\\file02\OP\" recurse="false" name="myList">
<cfdump var="#myList#"><cfabort>
I see that there is no list displayed although there are subdirectories and folders and files in the OP directory.
Does the folder needs any specific permissions to be read by any application or any other mapping required?
Here I will explain by using cf16. The ColdFusion runs in Windows as a service and if we look into all the services of the machine we will find as follow:
Here, you can notice that for ColdFusion service the LogOnAs value is "LocalSyatem". It means ColdFusion service is started as "LocalSystem" login and this login doesn't have enough permission to do any operation on network. So, in order to make the required file operation in the Shared Directory we will have to change the LogOnAs value for ColdFusion service.
Please follow the below step to enable it,
Right Click on the ColdFusion Service then click on "properties".
Click on "Log On" tab. Then you will see a screen like this
Select "This account" radio button .Then click on "Browse" button
and select the user by which you want to start the service. You
should choose the user who have sufficient permission to create file
on the shared directory and also have required permission in local.
But we have to restart the ColdFusion Service for the changes to effect.
Let me know if this work to you or not. Or correct me if I'm wrong understood.
I am new to working with Azure, but recently I have published my ASP.Net core 2 app to App Service and cannot access Email templates (.html) from within the API.
API works fine, it connects to the client side and to the database, but when I try and send out an e-mail - I get exception:
Could not find a part of the path 'D:\home\site\{ProjectName}\EmailTemplate\template.html'.
From within the code I call template using the following path format:
../{ProjectName}/EmailTemplate/template.html
How do I access these templates on a hosted environment?
Many thanks,
Alex
As per comments.
Right-click on the html template in vs and click Properties, then change Copy to Output Directory > Copy Always.
Also, as #jpgrassi noted, you can also add patterns in your csproj file to include a whole directory or even all files that end with .html. Just right-click on your project and select Edit <Project Name>. Then just add this:
<ItemGroup>
<Content Include="EmailTemplate\*.html" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>
I have a mp3 file in a folder called "audio" in Alfresco. I would like to have a link that points to that file in my index.html file which resides in another folder.
For example: <a href="pathToTheFile>test song 1</a>
How would I reference that file? I tried with href="/share/proxy/alfresco/api/node/content/workspace/SpacesStore/xxx-xxx-xxxxx/testMP3.mp3" and it does not work. Or is it even possible with Alfresco? I am using the web interface.
My apologies for not making myself clear. I am using Alfresco Explorer Community Edition for management, and the website I'm working on is based on Spring MVC and pulls content from index.html files in Alfresco.
Currently I need to use <embed> tags to include a mp3 file to index.html, and the mp3 file is also stored within the Alfresco repository but in a different folder.
How would I reference the mp3 file from the index.html file? The referencing has to work when the index.html is deployed to the client website, and currently the client website is referencing files in Alfresco in the following manner: <img src=/asset/xxxxxx-xx-xxx/test.png>(There is no asset folder in the Alfresco repository, and somehow that works...). But this does not work for my mp3 file...
To access alfresco content using the RESTful api, you should be querying this webscript: /alfresco/d/<d|a>/<workspace>/<store>/<nodeId>/<filename>
where :
d and a refer to direct / attached mode
<workspace>, <store> and <nodeId> reference your content nodeRef
<filename> a file name of your choice
So your URL should look something like this http://<host>:<port>/alfresco/d/d/workspace/SpacesStore/8444ad61-4734-40e3-b2d4-b8b1c81347fd/test.mp3
Note : Depending on the permission set on your node, you might need to attach an alf_ticket to the URL for an authenticated alfresco user. Please check this for further insights.
I have an application where I have an XML file which holds the connection string.
When hit the URL with the exact file name it opens the file in the browser that is natural.
Now I need to restrict this file browsing and I can not change that code to do any redirect or anything else.
What I have tried is using denyurlsequences in the security tag in the web.config but it restricts the application too to access the file and that makes the application stop working.
I am using .NET Framework 2.0
The ".xml" file extension is not supported by ASP.NET pipeline that is why you cannot add it to web.config and restrict it. What you can do is to copy the xml file in the "App_Data" folder of your application.
The purpose of this folder is to hide it files from browsers/users and also is build for this type of data.
To create "App_Data" folder if it already does not exist :
Right click on your project -> Add ASP.NET Folder -> App_Data
Or just add a folder and call it App_Data
I know its old question but this answer may be helpful for others.
I did below configurations on IIS 8.5 ( make sure Request Filtering is installed on IIS.)
Open IIS and click on your application virtual directory.
In features View, Click on Request Filtering and then go to Hidden Segments tab - this tab will contain list of hidden files or folders. (like web.config, APP_data folder etc...)
Add file or folder you want to hide from the browsing by click on add hidden segment and mention file/folder name you want to hide and test it.
In our application we have a master xml file stored in an application folder, to deny browsing this xml file I had added the folder name in hidden segments and it worked.