I m working in asp.net. I have created folders in my project folder and I want this to show on browser so that when users click on folder name it lists down all the files residing inside that folder.
Below i am attaching a picture which is a perfect example of what I want to do.
I have never done anything like this so i want guidance for this.
By default, if you enable Directory Browsing in IIS, a user can view like this -
However, it is not what you want in ASP.Net Application. Instead, you need to create a page with GridView or other data bound control, and bind it with Data.
If you want too fancy, you want to go with Commercial Components like Telerik FileExplorer.
Related
I'm developing a website in asp.net and now I need to convert it to a webapplication.
I created a new project with a new webapplication template and copy me files. I did a right click in the sollution and convert to webapplication and it worked fine, the vs2010 has created a design.vb files for each webform and it's good.
But, there are some webforms that uses some user controls and this user control doesn't created the declation in design.vb. I'd like to know if is there any way to fix the declations in webform to a my desing file to be used in code-behine ???
Thanks
You can right click on each user control and select Convert To Web Application (or something like that) individually to generate the designer files.
There is no easy way to do this through VS. You can alternatively try ReSharper's Adjust Namespace functionality.
I've a classified ads system on ASP.NET/c#/MS SQL, and I'm trying to figure out where to store the images that people upload when placing an ad. The ad itself is being stored in a SQL server database.
The images are now being stored in a subfolder of my webapp. It seems to work fine, however I only recently discovered a big problem. Everytime a user deletes an ad, the attached images are to be deleted as well including the folder they reside in. This leads to a restart of the asp.net application. I searched internet and found that restarting the web-app is actually intended behaviour when a subfolder is being deleted.
Obviously, I need to fix this. But how to do that? Where can I store images in such a way that:
I can remove these images including the folders they are stored in?
I can acces them using a URL (the images need to be shown in the
webpages)
Without getting the web-app being
restarted?
Any feedback is appreciated!
Paul
See this question Deleting a directory results in application restart
An other alternative would be to store the images in the DB instead.
Another option would be to put the images in a directory completely unrelated to the web site then serve the images through a scripted page or handler. It would make all of your image urls look like mydomaincom/serveimage.aspx?imageid=323422, but unless you're counting on the name somewhere that really shouldn't matter much. Obviously it would require a modification to the page that serves the images in the first place as well, but if sub directories of this unrelated directory are deleted IIS really shouldn't care at all.
maybe you can store the images in SQL (check at the filestream feature in this case)
if not, I suppose you have somewhere in a business facade class, a service class or wherever you want, a methode "DeleteAd".
This method will have to do two things :
-delete the sql data
-delete the file image
also, you may change the image store to another folder, outside the web app. You will probably end with writing a custom handler (myhandler.ashx?fileid=XX) to serve the files, or a custom route and control if you use MVC.
How can I make a dll of my web application usercontrol?
I have usercontrol222.ascx, but I want to make a dll out of this usercontrol.
Create a project containing only your user control ("usercontrol222.ascx") and grab the control's dll from the deployment of your new project. Here's the source of this method with a more complete explanation: Turning an .ascx User Control into a Redistributable Custom Control (Notable excerpts below, see the link for the full run-down).
Step 3: Use the Publish Command to Precompile the Site
The next step is to use the new
Publish command to precompile your
site and turn your user control into a
potential custom control. You'll find
the command under Build / Publish Web
Site. In the Publish dialog, do the
following:
Pick a Target Location. This is the location on your hard drive that your
site will be precompiled to.
Deselect "Allow this precompiled site to be updatable". In updatable
mode, only the code behind file (if
any) would get compiled, and the ascx
would be left unprocessed. This is
useful in some scenarios, but is not
what you want here since you want the
resulting DLL to be self-contained.
Select "Use fixed naming and single page assemblies". This will guarantee
that your user control will be
compiled into a single assembly that
will have a name based on the ascx
file. If you don't check this option,
your user control could be compiled
together with other pages and user
controls (if you had some), and the
assembly would receive a random name
that would be more difficult to work
with.
Step 4: Finding the Resulting Custom Control
Now, using the Windows
Explorer or a command-line window,
let's go to the directory you
specified as the target so we can see
what was generated. You will see a
number of files there, but let's focus
on the one that is relevant to our
goal of turning the user control into
a custom control.
In the "bin" directory, you will find
a file named something like
App_Web_MyTestUC.ascx.cdcab7d2.dll.
You are basically done, as this file
is your user control transformed into
a custom control! The only thing
that's left to do is to actually use
it.
You cannot. User controls are for the simplified scenario where you do not want to create a custom control. They have the disadvantage that the .ascx file and any other artifacts (images, styles, etc) must be included in each web site that uses the user control.
If you need complete reuse between projects, then you need to create a custom control. That's not actually that hard, if you directly translate the user control into a custom control.
You may want to look at developing your own server controls. See the following similar discussion: ASP.NET Web User Control Library.
I have upload control on my asp.net page. I upload pictures in folder cars and they show in windows explorer when I open that folder (cars), but in Visual Sudio they act like they not include in project ( that is the reason why they don't show on image control which point to some of them. What did I make wrong ?
Uploading the images in the web application will never make any changes to your project. You will have to add them manually if you'll need them there. But generally these are pictures added by your user so the would just be in the file system - not really part of the solution, are they?
If you have choosen a webSITE then it will allow this, but not if a webPROJECT is selected.
I didn't find this on net, but I had two projects, and the one which was allowing me to show uploaded files was a website.
You have to click the refresh button at the top of the solution explorer in Visual Studio for it to show changes to the files.
You have to click Refresh button. Also ensure that "Show all files" icon is selected. And finally, you will have to right click on the files and select Include in Project. That way it would become part of your project.
If I may ask, what exactly are you trying to achieve in your application? The reason I ask is, if there is an upload happening in your application, you shouldn't need to include the files in your project to refer to it from code.
I have a website which uses a web user control... well, basically all over the place. It's even included in other web user controls.
So I thought I could just upload the new source and it would recompile on the fly and be fine, but instead every page or control that uses it complains about a type mismatch. Because it is used in so many places, it very quickly becomes easier to just update the entire website. (Or at least it would if I didn't need to go through our change management process for that...)
So is there something I'm missing? Isn't there any way to upload a web user control and have it recompile like when you update a single web page?
I think it is recompiling, it just takes a bit and you have a conflict with the mismatched .ascx and .ascx.cs files in Temporary ASP.NET Files while it recompiles. I could be wrong about this. Personally, I've had better success if I always upload both the .ascx and .ascx.cs files together.
I would think that if you pushed these items you should be good... any less and you might have issues:
bin contents - this will include your code changes to the user control and if the assembly version changes you will want to include any .dll that use it, I have run into issues to many times by trying to push just a single .dll that is in the bin.
.ascx file
I don't think you would need to push any other .aspx or .ascx files.