Welcome to WebmasterWorld Guest from 54.242.193.41

Forum Moderators: ocean10000

Message Too Old, No Replies

Inserting a directory into a file path string

     
5:33 pm on Jul 29, 2008 (gmt 0)

New User

10+ Year Member

joined:July 12, 2008
posts: 12
votes: 0


I have volunteer to be a web master for a dog rescue group. The director of the dog rescue group wants a page counter on the home page.

I found a code example using asp.net and got it working very nicely in VWD on my computer. But when I loaded the code to my hosting server it fail. I found I had to make the directory which contain the page with the counter control read/write enabled. But I don't like using that setting for the pages that have all my webpages. I added a sub-directory, I called "Counter" I placed the counter.ascx file and the I use to store the count file in this directory. But I need to change one line of code in the counter.ascx file so that it will read and write to the counter file in the new directory. Right now it still wants to create/read/write the file in the same directory as the aspx file that calls the ascx file.


[2][b]strCountFileName = Server.MapPath(Request.ServerVariables("SCRIPT_NAME") & ".cnt")[/b][/2]

I think that "SCRIPT_NAME" is the name of the file that called the user control and that strCountFileName is the string variable that contains the complete path to the file that contains the current counter value.

In my case this is "..path\main.aspx.cnt" But now I what to make it equal to this "..path\Counter\main.aspx.cnt"

Thanks,

PhotoJoe

5:50 pm on July 29, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


SCRIPT_NAME gives you the location of the current control, ie. the location of the counter.ascx file. Here is some more info:
[4guysfromrolla.com...]

This should do the trick:

strCountFileName = Server.MapPath("~/Path/Counter/main.aspx.cnt")

* Edit - Forgot to add that the ~ means the root of the website, ie. if the control is located in

www.webiste.com/Path/Counter/Main.aspx.cnt
then the above line is correct.
7:12 pm on July 29, 2008 (gmt 0)

New User

10+ Year Member

joined:July 12, 2008
posts:12
votes: 0


Marcel,

Thank you for your reply.

In my example "Path/" was a fill in for the rest of the phyical path.

My testing shows that the count file that goes with the page that is being counted is created in the same directory as the aspx file (web root directory) and the ascx file is not in that directory, but in the counter directory. In my aspx file (main.aspx) I have the following lines of code.


[2]<%@ Register TagPrefix="asp101" TagName="Counter" Src="Counter\counter.ascx" %>[/2]


[2]<div style="background-image: url('images/Counter_BG.png'); width: 242px; height: 188px; text-align: center; vertical-align: middle; font-family: 'Comic Sans MS'; font-size: 24px; margin: 0 auto;">
<br /><br />
<span style="font-size: 48px;">
<asp101:Counter id="ctrlHitCounterText" runat="server"
Display = "text"
/></span>
</div>[/2]

I think I can use your code example to hardcode the counter file for this web page, but I was wondering how I would make it possible to use it for any web page that used this asp101:Counter (object?)

Thanks,
PhotoJoe

7:24 pm on July 29, 2008 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Feb 1, 2005
posts:733
votes: 0


<%@ Register TagPrefix="asp101" TagName="Counter" Src="Counter\counter.ascx" %>

You can change this to:

<%@ Register TagPrefix="asp101" TagName="Counter" Src="~/Counter/counter.ascx" %>

Assuming that ~/ is the root, as described in my previous post.

Add this to any page that you would like to use the control, and then use the code:

<asp101:Counter id="ctrlHitCounterText" runat="server" Display = "text"/>

to place the control in the desired position.

(I prefer the forward slash when pointing to a file or folder, as opposed to your example, but both should work)