Why do i see the " path " wrong - asp.net

i'm trying to import an excel file into my SQL table , i wrote a lot of codes but in visual studio my computer didn't see my path correctly. Example :
string path = #"~\Uploads\File1.xls"; here is my excel sheet its in the uploads file at my project file.
and i have this error : 'C:\Program Files (x86)\Common Files\Microsoft Shared\DevServer\10.0\~\Uploads\File1.xls', is not a valid path.

If your path is relative to your asp.net project, use:
Server.MapPath("~/Uploads/File1.xls");
Otherwise, use the full path

Related

I'm getting an error when I try to upload an excel file to my RStudio server

I'm using R Studio Server. When I try to upload a file from my desktop, I'm getting
Error: 'path' does not exist: 'data/sweets.xlsx'
This is the code I'm using to upload my file
sweetsimport <- readxl::read_xlsx('data/sweets.xlsx')
How do I fix this issue?
That path is not a path to your desktop. Assuming you are on a Mac and 'data' is a folder in your desktop with 'sweets.xlsx' directly inside of it, the correct path would be ~/Desktop/data/sweets.xlsx. Another way to get an absolute path on a Mac is to click a file and press option-command-c to copy the pathname.

File missing when packaging to jar file

I have a problem regarding exporting my Java project into a jar file.
I have this file (application.properties) which contains some database information and located under the project root directory.
There is no problem when running this project on Eclipse. But after exporting into a jar(Runnable Jar file) file, application.properties will not be included in the packaging and that cause the error.
Any suggestion how to fix this problem?
Do you want to have the application.properties reside outside the jar (for writing), or is it read-only? When outside you can have an initial template file in the jar, and copy it to some location.
//String applicationWorkingDir = System.getProperty("user.dir"); // The current constellation.
String userHomeDir = System.getProperty("user.home");
File myApplicationDataDir = new File(userHomeDir + "/.MyApplication");
myApplicationDataDir.mkdir();
File propertiesFile = new File(myApplicationDataDir, "application.properties");
Also using the Preferences API instead of a properties would be a solution.

to change the path of the file

I am trying to use fileupload tag to upload a file. What it basically does is, it saves the file into the follwoing directory:
C:\Program Files\Common Files\Microsoft Shared\DevServer\10.0\
Can someone please tell me how to change this path and save the upload file into some other directory?
You have the complete control of this. If you want to the file saved to a different path, then use this :
fileUpload.PostedFile.SaveAs("c:\my path\" + fileUpload.FileName);
Make sure it (folder) has permissions
FileUpload1.SaveAs(savePath);
read more about FileUpload.SaveAs Method

ASP.NET - Dealing with dependencies when using the debugger

When we run ASP.NET through the debugger it runs in a special directory like:
C:\Program Files\Common
Files\Microsoft Shared\DevServer\10.0
I dont know if this directory is configureable. The problem is that if you have a file such as Transfer.xsl then you set its property "Copy to Output Directory" to "Copy if newer". This copies the file out to the bin.
But, we are not running inside the bin. So if I use a relative path
StorageFolder\Transfer.xsl
It becomes...
C:\Program Files\Common
Files\Microsoft Shared\DevServer\10.0\StorageFolder\Transfer.xsl
But, Visual Studio does not copy files here even when you set the property described above.
In the past I got around this problem by writing a pre-build routine to xcopy the dependencies to this "temp folder". It works, but flippen sucks caseadillas.
Is there a better way?
In ASP.NET application you could use the App_Data special folder to store files. And when you want to get the full path to this file you use the MapPath method:
string fullPath = Server.MapPath("~/App_Data/Transfer.xsl");

ASP.NET reading files from BIN

I am processing some CSV file which i have copied in Bin folder of My ASP.NET Website.
When i execute
using (IDataReader csv = new CsvReader
(new StreamReader("sample.txt"), true, '|'))
{
.....
}
it complains me that "sample.txt" not found in "c:\Program Files\.....\"
Won't the runtime automatically look into the bin folder?
what modification do i need to do?
You need to specify a full path by calling Server.MapPath:
new StreamReader(Server.MapPath(#"~/bin/sample.txt"))
However, you should not put anything in the bin folder other than assemblies.
You should use the App_Data folder instead.

Resources