MVC Routing For Files With Muliple Sub-directories?

Aug 18, 2010

I need to setup a file handler to route with multiple sub directories something like tihs;

http://localhost/images/7/99/786936215595.jpg

I tried putting this in the global.asax file;

routes.Add(
"ImageRoute",
new Route("covers/{filepath}/{filename}",
new ImageRouteHandler()));

I am using the ImageHandler found in this Question, which works great if you have a single sub-directory (ie '/images/15/786936215595.jpg') but fails when you have multiple directories.

I tried setting up a wildcard and that didnt work (ie 'new Route("covers/{filepath}/*/{filename}"')

This is serving images from a large NAS (think something like 3 million images) so its not like I can just move files around.

View 2 Replies


Similar Messages:

How To Get Files In Vb.net In All Directories

Oct 25, 2010

This is in class file
Imports Microsoft.VisualBasic
Imports System.IO
Imports System.Collections.Generic
Public Class FileSrch
'' File Search Options
Public Enum FileSearchOptions
YearFirst
MonthFirst
DateinExtension
NormalFiles
End Enum
Public Shared Function GetSearchcriteria(ByVal DatetoSearchwith As Date, ByVal Filename As String, ByVal FileExtension As String, ByVal SearchOptions As FileSearchOptions)
Select Case SearchOptions
Case FileSearchOptions.YearFirst
Return String.Format("{0}_{1:yyyyMMdd}{2}", Filename, DatetoSearchwith, FileExtension)
Exit Select
Case FileSearchOptions.MonthFirst
Return String.Format("{0}_{1:yyyyMMdd}{2}", Filename, DatetoSearchwith, FileExtension)
Exit Select
Case FileSearchOptions.NormalFiles
Return String.Format(Filename + FileExtension)
Case FileSearchOptions.DateinExtension
Dim ExtensionFormat As String = (Convert.ToInt32(DatetoSearchwith.ToString("mm")).ToString() & DatetoSearchwith.ToString("dd"))
'' Month in Double Digit
If DatetoSearchwith.Month > 9 Then
ExtensionFormat = (DatetoSearchwith.ToString("mmm")(0) & DatetoSearchwith.ToString("dd"))
End If
Return String.Format("{0}.{1}", Filename, ExtensionFormat)
Case Else
Return String.Format("{0}.{1}", Filename, FileExtension)
End Select
End Function
Public Shared Function GetFiles(ByVal RootDirectory As DirectoryInfo, ByVal Filename As String, ByVal FileExtension As String, ByVal DatetoSearchwith As Date) As List(Of FileInfo)
Dim FiFiles As New List(Of FileInfo)
For Each DateOption As FileSrch.FileSearchOptions In [Enum].GetValues(GetType(FileSrch.FileSearchOptions))
FiFiles.AddRange(RootDirectory.GetFiles(FileSrch.GetSearchcriteria(DatetoSearchwith, Filename, FileExtension, DateOption), SearchOption.AllDirectories))
Next
Return FiFiles
End Function
End Class
This in Button Click
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FileName As String
' Dim fileName As String = txtextension.Text.Trim().Substring(0, txtextension.Text.Trim().IndexOf("."))
If txtextension.Text.Contains("_") Then
FileName = txtextension.Text.Trim().Substring(0, txtextension.Text.Trim().IndexOf("_"))
Else
FileName = txtextension.Text.Trim().Substring(0, txtextension.Text.Trim().IndexOf("."))
End If
Dim extensionToSearch As String = Path.GetExtension(txtextension.Text)
'Dim Directory As String = Path.GetDirectoryName(txtpath.Text.Trim())
Dim Directory As New DirectoryInfo(txtpath.Text.Trim())
'Dim filess As String() = Directory.GetFiles(txtpath.Text, txtextension.Text, SearchOption.AllDirectories)
'For Each fiFile As String In filess
' Response.Write(fiFile & "</br>")
'Next
Dim SearchedFiles As List(Of FileInfo) = FileSrch.GetFiles(Directory, fileName, extensionToSearch, Now.Date())
'Dim searchedFiles As List(Of FileInfo) = GlobalStuff.GetFiles(directoryToSearch, "whateverfilename", extensionToSearch, DateTime.Now)
If (SearchedFiles IsNot Nothing AndAlso SearchedFiles.Count > 0) Then
For Each fi As FileInfo In SearchedFiles
Response.Write(fi.Name & "</br>")
Next
Else
Response.Write("No files found")
End If
End Sub

Now,we need to address the following things in that to complete req, 1) If I enter filename_mmddyyyy.txt it should fetch only files having current date in their name in mmddyyyy format.For eg. If I give test_mmddyyyy.txt in txtextension it should return only files with test_10222010.txt and not thee ones with yyyymmdd and all...Right now I am getting all the files created in the current date including the one with ordinary test.txt and also test_20101022.txt .......And the third thing filename.mdd everything is getting passed correctly but it is not fetching the file ..Again test,test_20101022.txt everything comes.It shouldn't be like that it should only fetch files with .mdd (current date)....

In my above code i have two text boxes one for file path and other one for getting extension and also for gettting file names with diff search criteria.....What i do is i should implement file search which is like as mentioned below -

1) it should search for all files if i enter *.*,only jpg if *.jpg, and files like nks.txt if i enter ?

2) if i enter the filename alone without extn it should return me filenames that exist without extension in directories. 3) the final thing is the date in filename where my file will be like filename_mmddyyyy.txt or filename_yyyymmdd.txt or filename.mdd.In first case it should return only files with current date in mmddyyyy format and txt extn....like taht....last case is mdd in extn...

where if i enter filename.123,it sould get me files with jan 23(23 currnt date) and for months greater than 9 it is N for nov ,D for dec and so on.But in m,ytext box i will enter only file.mdd only .and also filename_mmddyyyy.jpg like that....

View 2 Replies

C# - Loop Through Directories And Search For .JPG Files?

Oct 15, 2010

I have this code and I'm getting an IOException and can't figure out what the problem is. I'm trying to loop through the subdirectories in a directory and list all of the .JPG files.

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Session["AllEmpsLoadPath"] = "\\intranet.org\Photo Album\Employees";
}

[Code]....

View 2 Replies

How To Add IIS Virtual Directories And Arbitrary Files In TFS Solution

Feb 11, 2010

We have a web portal product from which we customize portals from customers. We use the precompiled web app and create a virtual directory (vd) where the customization resides. In addition to this we do some changes web.config in the web app folder. We would obviously like to keep these customizations under TFS source control.

When I try to add the precompiled web app (which I don't want to add to source control), a warning tells me that the vds cannot be added. If I only add the folder that is referenced to by the vd, I lose the references to assemblies in the precompiled web app.

My questions are:

How do I structure a solution for adding IIS (sub application level) virtual directories and still retain the references to assemblies? Is it possible to add other directories/files from the web application level (like App_Theme, web.config etc.) to the solution?

Since we already use Visual Source Safe, we have established a tree structure for each customization project:

Project Root
|
|-Custom Sql
|
|-Custom Portal Files (which is added as a virtual directory)
|
|-Other Customizations

I could probably do a lot of this manually through the source control explorer, but I'd like to have everything done through a solution.

I've followed the instructions using this article: [URL], but this doesn't address the exact problem that I have. Oh, and we are currently using Visual Source Safe for portal customizaton, but are eager to make the move to TFS.

View 2 Replies

Web Forms :: How To Read Files From Directories Outside The Application

Feb 4, 2010

i have different number of directories containing files and i need to have hyperlinks so that user can download files to their ends. problem is that these directories are outside the application directory. how to map these files paths and name so that when user right click and save it on his machine or just clicking it..... what i have to do beside setting permission to reading those directories..

View 7 Replies

Moving Directories/files From The Server To Another Network Location?

Oct 5, 2010

In my asp.net wep application i would like to move the folders from the server to a network location so that the server doesnt get filled up.

i was able to move the files within the same drive but not to other network locations .

View 11 Replies

To Get Direct File Access To Files Within The Web Directories From .NET Application?

Jan 10, 2011

My ASP.NET application logs transactions (both inside AND outside of databases), and therefore needs read/write access to text files within various directories within the root of the website - in ADDITION to the normal database access.

In this scenario, how can I safely allow my ASP.NET application to write data to the web folders? I have a thread-safe DLL that performs the actual work, so I don't believe I need to worry about multiple sessions writing to the log files at the exact same time - assuming my DLL will only be running in a single instance/process that will be shared between numerous ASP.NET instances/processes/threads.

But I'm more concerned about file access permissions. I've heard that ASP.NET applications generally aren't allowed access to the webserver's local file system, and that this may even restrict my DLL from getting the correct file access. Can I grant my application file-access to the web-driectories?

View 1 Replies

Setup IIS 6 To Only Server Static Files From Virtual Directories?

Jun 21, 2010

We're having the same setup and receiving the same problem as:

[URL]

Setup
Server 2003 32bit, IIS 6
ASP.NET wild card mapping

A virtual directory mapped to an UNC share serving static images for a CMS in a load balancing environment

My question if it's possible to turn off asp.net from virtual and only serve static files e.g. images in the virtual directory, to avoid the problem with too many open connections?

If it's not possible I'll guess I have to implement a solution like [URL] to server the files from a local disc.

I found a possible solution at [URL] that removes the wild card mapping and makes it possible to turn of execution of asp.net files.

View 1 Replies

Enumerate The Directories And Sub Directories In A Windows Form Using A Tree View?

Feb 18, 2010

I'm trying to enumerate the directories and sub directories in a Windows Form using a Tree View. I can view the directories but when I want to see the files in the sub directories I only see the files from the root.

[Code]....

View 1 Replies

New To ASP: Creating A List Of Directories, Followed By List Of Files?

Jun 7, 2010

I've created a page that can list Directories and Files but when you click on the file link it posts back to the main page for some reason. If you can point me in the right direction....let me know.

[Code]....

View 1 Replies

Web Forms :: URL Routing - Local Files Become Inaccessible

Dec 22, 2010

I am using URL Routing in Asp.net 4. I have successfully got the url routing working, however i have encountered a problem with my web pages trying to access local files. For e.g. before i started using URL Routing, my web page was called [URL]. In this page i was making references to a CSS file and some Js files. They were referenced as follows : <link href="CSS/mycss.css" rel="stylesheet" type="text/css" /> and <script src="js/myjs.js" type="text/javascript"></script>. So basically i have two folders sitting on the route, called CSS and JS, containing the respective files.

However, after implementing routing my url has now become e.g. [URL] This is fine, but what has now happened is that my CSS and JS have become inaccessible as they are now referenced as follows: [url] or [url] i know i can sort of resolve this by referencing my files as follows

<link href="../../../CSS/mycss.css" rel="stylesheet" type="text/css" />
and <script src="../../../js/myjs.js" type="text/javascript"></script>.

But that means i have to change the path for every reference, and i have too many. Then also i must change the references to any background images for instance in my css to have the same path. This is a huge nuisance, and pain in the back side. Does anybody know of a solution for this, where i will not need to change the referencing for the files.

View 6 Replies

MVC :: Routing Not Ignoring Files That Exist On Disk?

Feb 21, 2011

I am testing with an MVC 2 project generated by the template in VS 2010. I have simply added an ADO.NET Entity Data Model, as well as a WCF Data Service that leverages the data model.

I was able to access the web application content (views, as well as the data served by the data service) just fine until the day before yesterday.

Yesterday I decided to reinstall Windows 7 on my development laptop, and I chose to go with the release of the OS with SP1. Of course, I reinstalled Visual Studio as well.

Now the same project gives me HTTP 404 errors when I try to browse to the data url .../MyTodoDataService.svc).

Here are some interesting facts:

The same data service works just fine in a Web Forms application. I see the problem only when deploying to the Local IIS Web Server (Cassini runs it just fine).

I am able to browse to the data url if force MVC routing to ignore the appropriate route by calling "IgnoreRoute" on the RouteCollection in Global.asax.

View 7 Replies

Web Forms :: Inheritance And Interface/abstract Method To Be Implemented On Muliple Aspx Pages?

Dec 13, 2010

I am working on a asp.net reporting project using crystal reports. I am a little new to working on making the project dynamic or reducing down code.

I have many aspx pages which are using the same logic of collecting input from textboxes and inputing to business logic layer.

I was thinking if someone can suggest me inheritance and interface/abstract method to be implemented on muliple aspx pages?

View 9 Replies

C# - Block Access To Files When Using The System.Web.Routing.UrlRoutingModule?

Jan 22, 2010

I'm using the System.Web.Routing.UrlRoutingModule.

With that I'm writing:

routes.Add(new Route(@"cart/add", new RouteHandler("~/Order/CartAdd.ashx")));
routes.Add(new Route(@"cart/delete", new RouteHandler("~/Order/CartDelete.ashx")));

And I also have one route called:

routes.Add(new Route(@"{*url}", new RouteHandler("~/Error/PageNotFound.ashx")));

But if I go directy to /Order/CartAdd.ashx I never enter the routing. It goes directly to that handler. And if I go to /Order/ I get a 403.14 error.

How do I instead catch those urls with the routing?

View 1 Replies

Security :: URL Routing Doesn't Work For Files In Admin Folder

Jun 24, 2010

I am using URL routing in asp.net application (not MVC) . I have Admin folder in my aaplication which has admin related aspx pages with seperate web.config. I have seperate login form for admin users which is placed in admin folder itself. My issue is whenever I hit [URL] (which I want to go to login form for admin)- it tries to authenticate and goes to login url mentioned in web.config of root folder.

Note: Admin folder has anonymous access in root config file. Also I have set default document in config of Admin folder. I have added following line in global.asax so that routing doesnt work for files in admin folder;

routes.Add(new
Route("admin/{*resource}",
new
StopRoutingHandler()));

I am really confused what is the issue? What I am missing?

View 6 Replies

Web Forms :: Web.Routing Doesn't Work On Server On IIS Routing

Jul 20, 2010

I tried everything I could find, but still does not work on IIS routing.

View 2 Replies

Routing With Web Forms - Could Not Load System.Web.Routing

Dec 12, 2010

I am using:

ASP.NET 3.5 SP1 with Web Forms Routing thru Global.asax (System.Web.Routing and RegisterRoutes)IIS 7

Everything is working fine in my local machine, but it gives the following error in my hosting environment:

Could not load file or assembly 'System.Web.Routing, Version=3.5.0.0, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.

I did everything inside my web.config file mentioned in the following link:

[URL]

But I am still getting the above error.

What else am I supposed to do fix the error?

View 1 Replies

Rest WCF Url Routing & Web Forms Routing?

Feb 22, 2011

I have a Web application where i have added a reference to a RESTful WCF. I got the WCF url Routing to work in my webapplication by adding Inherits="RestService.Global" to the Web applications Global.asax.

<%@ Application Codebehind="Global.asax.cs" Inherits="RestService.Global" Language="C#" %>

But then i tried to create url Routing for the Web application and it does not work with the Inherits="RestService.Global" in the Global.asax. If i take it away it works fine. Is there a correct way to do this.

View 1 Replies

Web Forms :: URL Routing And Dynamic Routing?

Jan 31, 2011

I'm trying to create my own CMS and I've gotten a little bit stuck at the stage of URL routing.

I want clean URLs without extensions and I'd like to be able to create and modify them in a web based interface without any messing around with IIS or actual files.

I've seen how to create a static route, but for that I need to go into my Global.asax file and manually add it.I would like to have all of these routes stored in a database so that I can easily modify them later.

Does anyone know how this can be achieved?

Just for extra information, I will be attempting to create a feature so that if a path exists, but is later changed, a 301 redirect is created to the new URL, is this also possible? (My first problem is the main issue, but thought I might ask this as well just in case it makes a difference)

View 2 Replies

Handle MVC Routing Along With Webform Routing

Sep 2, 2010

How to handle asp.net mvc routing along with asp.net webform routing. I have merged my mvc app into my existing web application. In my web application i have implement routing as below:

routes.Add("View Product Details", new Route("Product/{City}/{Manufacturer}/{Name}/{ProductID}/{*ProductType}"));

Similarly i have implemented routing in mvc as below

routes.MapRoute("Product Details",
"Product/{City}/{Manufacturer}/{Name}/{ProductID}/{ProductType}",
new
{
controller = "Home",
action = "ProductDetails",
City= UrlParameter.Optional,
Manufacturer= UrlParameter.Optional,
Name= UrlParameter.Optional,
ProductID= UrlParameter.Optional,
ProductType= UrlParameter.Optional
});

How to handle both pages, as one is custom web form while other is asp.net mvc view?

View 1 Replies

App_localresources Not Working With Directories?

Apr 13, 2010

i have a test project with the following directory structure:

/root/pages/default.aspx

/root/App_LocalResources/default.aspx.resx

/root/App_LocalResources/default.aspx.fr.resx

using the following simple code:

[code]....

View 4 Replies

C# - Create Virtual Directories In IIS 7.5?

Jul 25, 2010

My asp.net web application knows how to create sub-applications (asp.net applications with web.config file, located in sub folders of the root application).

Now, I need to configure each sub-application in the IIS with a Virtual Directory, AND, make this new virtual directory an application in a specified application pool.

Is there any API for IIS7.5 using .NET ?

View 1 Replies

Setting Up App On A Vps / Need To Set Any Of The Folders As Virtual Directories

Sep 16, 2010

I just got a windows vps setup at a hosting company and about to install a big web application that is a store front. Do I need to set any of the folders as virtual directories? I'm so confused on all of this. Do I just copy the folders and files over and thats it? It has Plesk to use for the control panel. I know I have to set the directories to run as application but is there anything else?

View 1 Replies

Can Upload Entire Directories Using Uploadify

Mar 3, 2011

I am using uploadify along with ASP.NET to upload files to my server. At the moment I have to recreate the folder structure and upload the images in batches per directory.Does anyone know of a way of using Uplodify or any other tool that would allow me to select a folder and upload the entire directory?

View 2 Replies

How To Set Virtual Directories Dot Net Framework Version 2.0 To 4.0

Oct 20, 2010

I have installed VS2010. already i have VS 2005 and website working with framework 2.0.After installation, now I am unable to set ASP.net version for IIS virtual directories to Dot net Framework verion 4.0.How can i set virtual directories Dot net Framework version 2.0 to 4.0?

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved