Get VB.NET Relative \Upload path to the running application? - asp.net

I found my trouble spot I think may be only because I am running the app on localhost, but I dont feel I can safely deploy to the next tier to test.
I have a Telerik RadAsyncUpload control that has a TargetFolder="\Upload" and was assuming all along it would use the \Upload folder in the application.
Is there a way to force the path to be inside the application?
lsFullFileName = HttpContext.Current.Server.MapPath(fuUploadFile.TargetFolder)
+ "\" + Path.GetFileName(lsFileName)
This is in VB.net. and the file is ending up in "C:\Upload" (which I created to see what was going on) but the file should be moved from its temp location in App_Data to
"C:\applicationName\applicationName\Upload"
ASPX
<telerik:RadAsyncUpload
runat="server"
ID="fuUploadFile"
MaxFileSize="262144000"
OnClientFileUploaded="OnClientFileUploaded"
InputSize="50"
TargetFolder="\Upload"
AllowedFileExtensions=".wav,.mp3,.mpeg,.mpg,.wmv,.avi,.mp4">
</telerik:RadAsyncUpload>
Thanks.

If you're insistent on keeping your upload directory within your site folders, then you can use a path like ~\Upload which will force the path to start from the web application root.
However, this is generally a bad idea as Bartdude outlined.

Try this:
uploadPath As String = AppDomain.CurrentDomain.BaseDirectory & "Upload"

Related

Specific path to a text file on an ASP.NET server application

I would like to set a path to my text files which are stored in TextFiles folder. Project looks like that:
This application is already hosted on a website. I've tried almost every combinations of Server.MapPath like ("~/TextFiles/UserItemReturnMail.txt"), ("./TextFiles/UserItemReturnMail.txt"), ("\\TextFiles\\UserItemReturnMail.txt"), etc. How can I get to those files, because I have no idea now.
Try this :
Server.MapPath("."), Server.MapPath("~"), Server.MapPath(#"\"), Server.MapPath("/"). What is the difference?
and
How to use Server.MapPath to get location outside website folder in ASP.NET
and this official :
https://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath(v=vs.110).aspx

Find the path of browser default downloads folder

how can we find the path of browser default downloads folder in c# / asp.net?
For example I can get the path of user desktop like :
Environment.GetFolderPath(Environment.SpecialFolder.Desktop)
Thanks..
You can't find that out in a web application. It's up to the user to decide which browser to use and how to configure it and where to save downloaded files by default and you have absolutely no way of interfering or even knowing his choices from a web application.
First of all looking at MSDN on Environment.SpecialFolder there is no download folder, and the reason is that this is different for every browser.
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx
And there have nothing to do with asp.net, if you look it from the server side you just get a directory on nowhere, meaning that this have nothing to do with the web application that run under the pool.
What you can do
You can use the HttpRuntime.AppDomainAppPath and use it to know where your site lives, and there place a "download" directory and use this full path:
HttpRuntime.AppDomainAppPath + "download/"
for download/upload files.

ASP.net relative paths not working?

This should be pretty simple but it's not working.
I have a file underneath the root of my project. I want to call it like this.
GetWorkbook("tplBud806_wRevenue.xls")
I publish the project out to the server and try to run it and the server says it can't find it.
Could not find file 'c:\windows\system32\inetsrv\tplBud806_wRevenue.xls'.
That's not the path it should be taking. It should be under E:\IIServer\rootwww\reports\tplBud806_wRevenue.xls.
I thought relative paths were supposed to start from the path that the project was running in. I've also tried.
GetWorkbook("/tplBud806_wRevenue.xls")
GetWorkbook("\tplBud806_wRevenue.xls")
GetWorkbook("~/tplBud806_wRevenue.xls")
GetWorkbook("~\tplBud806_wRevenue.xls")
Is there some setting I'm missing? It's got to be something simple...
GetWorkBook(Server.MapPath("tplBud806_wRevenue.xls"));
GetWorkbook is not an ASP.NET function, and it likely defaults to the folder that the process calling it was started from. The process in this case is an IIS process and probably started in that folder.
Server.MapPath?
Your application is running in an AppDomain loaded by the w3wp.exe located in the directory in your error. Which means that trying to look for any file will start in that directory. You should use Page.MapPath, as mentioned by others. It tells the application to start looking in the folder your aspx is in.
GetWorkBook(Server.MapPath("~/tplBud806_wRevenue.xls")); If the .XLS file is at the root of your project.
You can use also use ~ in conjuction with ResolveURL() to access an URL in your site. So ~ will be replaced by the root URL of your project
Example:
ResolveURL("~\tplBud806_wRevenue.xls")
will be transformed to
http://myproject.url/website/tplBud806_wRevenue.xls
If you need disk access, like in your example, use Server.MapPath
Look at this SO post to learn more about Server.MapPath

Can't get FCKEditor to work in a virtual directory

I have a WebForm that contains the following definition for the FCKeditor:
<FCKeditorV2:FCKeditor ID="txtBody" runat="server"
BasePath="/fckeditor/"
Height="480px"
ToolbarSet="WebCal1"
>
</FCKeditorV2:FCKeditor>
This works fine in my VS2008-based web application. However, when I deploy it to a Virtual Directory in IIS, it looks for the FCKEditor files (e.g. javascript, stylesheets, etc...) in the /fckeditor folder, not in the /MyVirtualDir/fkceditor.
I've tried changing the BasePath to ~/fckeditor/, but then it won't work on my dev machine.
What is the right way to go, so that the FCKEditor maps onto the right directory. In my project the fckeditor directory is right off the root.
I user "~/fckeditor/" without a problem on both virtual directories, root directories and local machine.
Do you think something else could be going on? What does Firebug say is happening?
I figured it out. The piece that was confusing the FCKEditor was the SkinPath. When I'd set the BasePath to "~/fckeditor/", it would path this string + the path of the skin to JavaScript (e.g. ~fckeditor/editor/skins/office2003). And javascript could not resolve the relative path.
So the solution is to place this code in the form Page_Load event:
txtSignature.SkinPath = Path.Combine(this.ResolveUrl(txtSignature.BasePath), "editor/skins/office2003/");

Where does the ASP.NET development server get its images from?

In my web application I dynamically generate images and want to show the images as part of a web page.
But, when debugging using the ASP.NET development server (not IIS) - I have no idea where to store these images so they can be referenced from my web application.
Should I use Directory.GetCurrentDirectory()?
Or Assembly.GetExecutingAssembly().Location?
Or Assembly.GetExecutingAssembly().CodeBase?
None of these paths seem to work.
Any ideas?
Server.MapPath("~/") will give you the path the the root of the web application. Everything placed within the scope of this path should be automatically exposed by the web server, be it IIS or the VS devevelopment server.
The Server property is available in to all Page objects, and can otherwise be found on the HttpContext.
You can use
Server.MapPath()
You can write ashx handler to server images on the fly. Here is tutorial for this. It you want to generate and display them later then create a folder in your web-site folder tree and get its physical path using this:
string imgPath = Server.MapPath("/") + "Images\" + IMAGENAME;
Make a seprate aspx page, and put your code overthere that create your dynamic images..
your code should be look like....
Response.ContentType = dtblProductImage[0].ImageFileExt;//image extension
Response.BinaryWrite(dtblProductImage[0].ImageData); //your image binary
now go to that page where you want to show your image and set the image property of imageURL to your page, it will look like this....
<asp:Image ID="imgProduct" runat="server" ImageUrl="yourpage.aspx" />

Resources