Get chrome downloads folder - c#

The default downloads folder in Windows 7 is c:\users\username\downloads for Chrome. But default downloads folder can be set to another folder through settings. I need to find out which folder is the downloads folder. So if I set the downloads folder to c:\dd, then I need to find out the specific folder.
Is there a way of finding this out using C#? I mean I don't want to visit the chrome settings and fetch the folder path from there.

The default locations for Chrome settings are here. I actually found mine to be under 'C:\Users[UserName]\AppData\Local\Google\Chrome\User Data\Default' for Chrome 20.0.1132.47.
If you open the Preferences file, you can parse the JSON to get the download folder:
"download": {
"default_directory": "C:\\Users\\[UserName]\\Downloads",
"directory_upgrade": true,
"extensions_to_open": ""
}
If there is no default_directory value, then the directory C:\Users\[UserName]\Downloads is being used.

Related

Change IE default File Browsing Folder

When you need to upload a file using IE, a file browsing dialog will open and let you choose a file.
In future whenever you try to upload a file, previously selected file's location will be displayed as first folder in file browsing dialog.
After some researches I find out opened file's information will save in this location of registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU
I need to Change IE default File Browsing Folder from code.

View files with Hyperlink ASP.NET

I have a directory containing files (images , pdf ..etc).. then I've got all the directory files with c# code and viewed them as a hyperlink for each file to be able to view each file in the browser.
when I click on the pdf file link for example , it doesn't view the file .. but when I copy the link address of the pdf file , then paste and view it in a separated window . the pdf file open normally.
when I view the source code of the page I find that the link for the pdf file as it is in my local machine directory not the server one.
Please help me with that..
Thanks.
Its a security issue. In console, you must be seeing the error "Not allowed to load local resource". On clicking the anchor tag, which contains the absolute path to local file, the file has to be served by the IIS server(as the page is web page, which is loaded from asp.net application), which is not allowed.
In a web application, if you provide local file path to a file in your webpages, you are making the assumption that the file exists on the clients computer or device and not on your server.
So, create a folder inside your applications root folder and just give relative path to those files in anchor tag that includes hostname like
http://myserver.com/aspnet.pdf

How to give a folder path in app.config file in C#

I am creating an application in WPF.
In that I am using XML file to store some settings.
My app will run for every 10 sec. So it will use that XML file settings.
My issue is in My local system i am calling the XML file as D://Foldername/projectname/test.xml .
But after deployment it is storing in C://Programfiles/Projectname/test.xml .
So how to give a generic path so that it runs in all the client systems.
I am creating setup file to install in clients systems.
Please help me.
Open the project properties page.
Click on Settings tab.
Add a new item called "MyPath". Make it an Application Setting of type String and give it a sensible default path name as value.
Reference the value in code with Properties.Settings.Default.MyPath.
If you open the applications config there will be a setting called MyPath where you can override the path at runtime.
I suggest you to put the XML file in the same folder as your EXE file and then use Assembly to get its current path.
var cfgPath = Assembly.GetExecutingAssembly().Location + ".config"
Update
it's better to name your config file the same with your exe file but with ".config" extension.
If you are really using ClickOnce, I hardly recommend you to create your own directory for data and configuration files:
private static string GetDataDir()
{
var dataDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"YourApplicationName");
if (!Directory.Exists(dataDir))
Directory.CreateDirectory(dataDir);
return dataDir;
}
The problem with storing the data in the directory of the executable is, that it will be at a different location. While debugging, it will be in you \bin directory. When the application is deployed by ClickOnce, you gonna have a bad time. The installation directory for a ClickOnce application is created for every version. So if you EVER update your application at "customers", all their settings will be lost.

get file path for file included in project

I am building an integration test with Selenium and need to upload a file. I have the file included in my project but I need the full path to enter into the browser, to check if the browser upload system works.
How can I get the full path of a file that is included in my project? The test will be run on several different machines from different locations.
You don't need to. Mark it as 'Copy To Output Directory' (right click in Solution Explorer and look at the props) and it will always be in your working dir and so you can use a relative path, e.g.:
new StreamReader("myFileThatIMarkedAsCopyAlwaysInVisualStudio.txt");

Folder and file not added to User's Application Data folder

Ladies and Gentlemen , I have been stuck with this for a few hours and do not find an answer. I have a Setup project in Visual Studio that creates an installer for my C# application. What I want is to add a folder with an XML file from which my application can read and write to the User's Application Data folder. In the File System Editor window I added the User's Application Data folder. In this folder I added a new folder (renaming it to my app's name) and then place the XML file in there. I also set the AlwaysCreate to true for the folder. The installer should create the folder in C:\Users\UserName\AppData\Local and add the file to it. However, the installer does not create the folder or the XML file my application uses. What am I missing? Is there another way to install a read/write XML file? Thanks in advance!
Ok, I found what the issue was. If a file is added to the User's Application Data folder it is installed on the target computer at C:\Users\Username\AppData\Roaming and not into AppData\Local.
Therefore, I changed my application get the file from Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) instead of Environment.GetFolderPath( Environment.SpecialFolder.LocalApplicationData).
Hope it helps someone else...

Categories

Resources