Getting a directory's path, that is inside an assembly - asp.net

I have a custom asp.net control. That control will also render to the page a piece of javascript. This javascript piece of code is actually properties that have to be initialized. One of this property value must be a path. This path is a directory that is inside this assembly. If it is was a file i would use GetWebResourceUrl but now I don't know what commands to use.
Also I would like to know, if I get the dir path the files inside it will be available for the javascript to use them or not?

Try this: System.Reflection.Assembly.GetExecutingAssembly().Location

Related

Jade - calling page specific css pages

I have page specific css files I would like to call automatically. Does anyone have a nice way of doing this elegantly?
This should do it
link(rel="stylesheet", href="#{req.path + '.css'}", type="text/css")
Where you pass either req (the request object) as a local variable when rendering the jade template (or even just pass in req.path as path). This could just be handled in your layout.jade and it will work for each of your route paths.
If you want to get fancy, you could establish a consistent pattern where a page's route maps 1 to 1 to a filesystem path for a .css file in your public directory. In that case you could easily but the stylesheet link tag inside a conditional and only link to the .css file if you find a matching one on disk.

Using directives in new files

Is it possible to have additional "using" directives automatically added to my new aspx.cs files so that I do not have to keep typing the same ones over and over again (i.e. custom namespace using directives)
You can edit the files that are used by the template. Better yet, create your own. File + Export Template.
You don't have to type them in. When writing the code, type in the name of the class (without the namespace). Then hit CTRL+.. That will open up the resolve type intellisense helper. It will add the using statement to the top of the file. No scrolling necessary.

Flex Builder: Not picking up new files

I have a working AS3 project and it compiles fine to a SWF. I added a new file (via various means: import, drag-drop, new), but it doesn't compile this new file. I'm using Flex Builder 3. I've tried a clean an rebuild. I've tried renaming. It picks up the existing files fine, but not the new one. The project is set to use a HTML wrapper. I see some build files (I think). The new file is in an existing folder and package.
Any idea what could be wrong?
First, the SWF Compiler will optimize your end code. If you never use a class or create an instance of it anywhere in your application; that code will never be compiled in your application. this is a common occurrence if you're using Flex Remoting with some backend; and a VAlue Object is never instantiated directly, instead you're always returning arrays of it. You'll find you get a lot of "Generic Objects" without the backend object-to- AS3 object translation of the Flex Remoting Gateway.
You didn't specify what type of file you are adding. If it is an ActionScript file it won't automatically be compiled in the swf. You'll have to 'include' it in another class somehow. IF it is an ActionScript class or MXML Component, make sure you are using that class somehow in your code. If it is another file type, such as an image or other asset you'll have to embed that file into your code somehow.
We might be able to offer more help if you were to tell us what type of file is not being added to the final SWC. Also tell us how you can tell.

asp.net path problem when deploying

We have moved a lot of images and javascript file that was inside class to external Javascript file. In development (Debug inside Visual Studio), everything look nice, all images show, all javascript works and all CSS display perfectly. When we do a package and install with IIS ina virtual directory everything that is pointed by the JavaScript doesn't work.
Question : Since we cannot use the tilde (~) in javascript or in CSS what is the way to display those resources?
Edit 1
The problem is the website is installed with a Virtual Directory and if we have in the JavaScript file a popup that has a hardcoded path in the JavaScript the code try to display : "http://localhost/NameSpace/Directory/File.html" instead of "http://localhost/VIRTUALDIRECTORY/NameSpace/Directory/File.html". Is there a configuration with IIS or inside the code I need to add something like a parameter to pass the path everytime?
In the javascript in dev it work to have something like :
var popWindowPath = '/ProgressFile/Simple/ProgressSlow.htm';
Images for css are, I believe, displayed relative to the css file so that shouldn't be an issue (use relative rather than absolute links).
For the js, either have the ability to pass a base link in as an argument or make .js files parsed as .net pages and include code on those pages.

How to access serverside context from `.js` file?

I have to move all my scripts into a separate .js file. But I have wired the code in the client (*.aspx) file, with code such as
<script>
var x=<%=ViewData["Key"];%>
</script>
I'm sure there will be an issue when I move that line to the js file as the server side context can't be accessed.
How do I solve this issue?
The most straightforward thing to do is to move all JS code except these variable assignments.
Effectively, the trick is dependency injection in javascript. First, abstract the variables you are generating from server-side variables into parameters for your javascript methods and objects. Then use a small amount of script in-page to setup the javascripts to run.
If you are dealing with a few rather static things (eg--some path names), another tactic is to create a javascript "configuration" object that is in a separate, server-generated script, that can be called by your other scripts as needed.

Resources