简体   繁体   中英

ASP.NET Server Control - Thousands of Embedded Files?

I have created an ASP.NET Server Control and have it working just fine. However, I have decided that I now need to embed many, many images into the DLL rather than having them be required in local paths wherever the DLL is used.

To my horror I just discovered that doing this is a manual job where I have to go into hundreds of folders and subfolders and specify that I want those files to be embedded. I then have to change all of my markup to read these images and files via the WebResourceAttribute which is a chore to say the least.

My 2 questions:

  1. Is there a quick way to embed hundreds of folders and subfolders worth of files with a few clicks?
  2. If so, is there a way to simply reference these files as if they were on the file system? In other words, can I do a global search and replace for something like this:
    • Find:
      • script type="text/javascript" src="folder/
    • Replace With:
      • script type="text/javascript" src="{WebResourceStuff}/
  1. Assuming your images are already included in the web project, you might consider writing a Visual Studio macro to traverse your project folder structure and embed all the images. If they aren't, you can still do the same thing by using the System.IO.Directory class.

    To get the right macro code to embed the image, turn the macro recording feature on and embed a couple of images. That should cause the right macro code to be generated. (Assuming this can be done with a macro, of course.)

  2. Yes, you can definitely do this. Try the Find in Files feature of VS and use the Replace option.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM