How to open folder from web page - asp.net

I want to open folder from web page on clicking on a button.
protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("file://C://inetpub//wwwroot//myproject");
}
Please suggest me proper code in C# for open myproject folder.

This can be ONLY done in IE, no other browser has access to file system. You can assign the path to href of an anchor tag, and it should work.
Open

If you're looking at adding functionality to your website so that a user can upload files to it then look at this project on MSDN. It'll show you how to do this with an example ASP.NET project.

Maybe this statement can help you:
System.Diagnostics.Process.Start(#"C:\");

Related

AjaxFileUpload don't flush %windir%\temp\

I have a considerable issue, found by hosting several ASP.NET websites (7 ~ 15) with the AjaxFileUpload server control of the AjaxControlToolkit library (the latest version):
while the control is processing file, temporary files are saved in the system temporary folder (%windir%\temp), but it won't flush that after the request is complete.
I don't know if this is a folder permission problem, or an AjaxFileUpload bug.
This is the result after 2 years of hosting, a huge stack of temporary folders:
Top
Bottom
There is any way to override that behavior, or i must manually flush that folder every 1-2 months ?
Thanks in advance
If you don't use SaveAS() method, you must deleted yourself.
example:
protected void AjaxFileUpload1_UploadComplete(object sender, AjaxControlToolkit.AjaxFileUploadEventArgs e) {
// Save uploaded file to a database table
e.DeleteTemporaryData();
}
more info here: http://stephenwalther.com/archive/2013/04/30/april-2013-release-of-the-ajax-control-toolkit

url rewrite in asp.net for dynamially generated urls

I have few dinamically generated urls like http://localhost:35228/begineercontent?name=lanaguages&id=23, I used routing to hide .aspx extension and now i want to see above url like this http://localhost:35228/begineercontent/lanaguages/23 i tried few url rewrite methods from iis url rewrite tool nothing worked kindly please help me out
This can be done very easy. You need to change/add this code in your global.asax.
void registerroute(RouteCollection routes)
{
routes.MapPageRoute("begineercontent", "begineercontent/languages/{Id}", "~/begineercontent.aspx");
}
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
registerroute(RouteTable.Routes);
}
You also need to include the right assembly in global.asax by adding
using System.Web.Routing
In your begineercontent.aspx you need to add this code to the page load function.
var Id=( Page.RouteData.Values["Id"] as string);
A more detailled tutorial on how to work with routes can be found here:
http://msdn.microsoft.com/en-us/library/vstudio/cc668177%28v=vs.100%29.aspx

Adding Cache headers via a Web.config for specific locations only

We have an application that has been developed by the third party, and I don't want to go back to them to get them to add in cache control for specific pages.
All the pages that need caching disabled are in a single directory.
The issue is that IE seems to not follow Cache-control:nocache properly, so we need to add in Pragma:nocache and cache age as well.
Is there a way to do this using configs in the directory? will it cascade through all child directories? Can it be done via the main web.config?
To be clear, I'm not looking for a way to do this via code, it needs to be via configuration of either IIS or the web.config files.
We're using ASP.NET 2.0 and 4.0, on IIS 6.0.
This can be done in IIS using the UI, it's actually quite easy, or atleast it was in my use case.
All you do is simply open up IIS manager, navigate to the site and then the directory you want to add the headers to Right Click -> properties.
Click the "Headers" tab, and add in the headers you require.
This goes recursively down the child directories, and adds the headers before any added by the code.
In IIS 7.0/7.5, you can use the StaticContent section of a web.config in each of the directories.
You can do that on global.asax
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpApplication app = (HttpApplication)sender;
string cTheFile = HttpContext.Current.Request.Path;
if (cTheFile.Contains("/ExtraDir/"))
{
// add your header here
app.Response.AppendHeader("Pragma", "no-cache");
}
//... rest code of...
}

getting back to folder in asp.net

protected void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Page2.aspx");
}
this is code to go on .aspx but what if i want to go in Folder in my solution explorer, tried with location but it dont work
Who knows post it.
this is location >
website\admin
-news.aspx
-project.aspx
and i created in news.aspx button go back to admin, and when i hit button location is next > website\admin\admin why he duplicate admin ?
Response.Redirect("~/Folder/Page.aspx");
The tilde ~ is very useful for redirects, it signifies your site root. So wherever you are on the site, you can redirect to folders relative to the domain root. I hope this is what you meant!
if you have admin folder in your application then redirect it
Response.Redirect("admin/page.aspx"); or
Response.Redirect("~/admin/page.aspx");
if you don't have admin folder in your application then redirect it
Response.Redirect("page.aspx");
Try this all ...

using dll extention instead of the standard aspx

I am replacing an existing web application, that all it's requests go through a url:
www.something.com/scripts/xxx.dll?args
I created my own aspx page that handles these requests and it is called:
www.something.com/scripts/xxx.aspx?args
My problem is that there are many existing links, from other website that refer to the xxx.dll?args url.
Can I create my own dll in .net that will receive the xxx.dll?args requests and process them?
This isn't a simple redirect, because I also need the args
I'd suggest to rather use Url Rewriting
After some more investigation I did the following.
Change the web.config, to make sure all requests go through my code by adding the following code:
...<system.webServer>
<modules runAllManagedModulesForAllRequests="true">...
Added a global.asax file to the web project, and within it wrote the following code:
protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Request.Path.EndsWith("xxx.dll",
StringComparison.InvariantCultureIgnoreCase))
Context.RewritePath("/scripts/xxx.aspx");
}

Resources