Microsoft Content Management Server - Header.ascx and Dynamic Images

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > November 2005 > Header.ascx and Dynamic Images





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Header.ascx and Dynamic Images
bhprogrammer8

2005-10-24, 10:39 am

I am new to CMS. I have been assigned to a half finished project, and have
not been involved from the beginning. I would like to change the Header.ascx
file which includes a LOGO image in the upperleft corner, to dynamically grab
the correct image based on which CHANNEL the visitor is browsing. I am
digging through 3 different MCMS books, and online tech docs and forums, but
cannot figure out this seemingly easy task. The site is done in C#, i am
used to VB, but making my way through it.
I have assigned custom properties to each channel with a name "LOGO" and a
value "channelname.jpg". I am sure there is a method of Getting the Channel
Name and displaying the image based on the property for that channel.
Can someone please point me in the right direction using CMS?
Seems so easy, but this product has so many options.

Thanks in advance.

Björn Bur

2005-10-24, 10:39 am

hello...

you can access the channel object and it's custom properties by using the
cms api as followed...

CmsHttpContext.Current.Channel.CustomProperties["CustomPropertyName"].Value

greets

björn


"bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
news:58BDC5BB-E52B-48E5-ACC8-702469156024@microsoft.com...
>I am new to CMS. I have been assigned to a half finished project, and have
> not been involved from the beginning. I would like to change the
> Header.ascx
> file which includes a LOGO image in the upperleft corner, to dynamically
> grab
> the correct image based on which CHANNEL the visitor is browsing. I am
> digging through 3 different MCMS books, and online tech docs and forums,
> but
> cannot figure out this seemingly easy task. The site is done in C#, i am
> used to VB, but making my way through it.
> I have assigned custom properties to each channel with a name "LOGO" and a
> value "channelname.jpg". I am sure there is a method of Getting the
> Channel
> Name and displaying the image based on the property for that channel.
> Can someone please point me in the right direction using CMS?
> Seems so easy, but this product has so many options.
>
> Thanks in advance.
>



Stefan [MSFT]

2005-10-24, 10:39 am

Hi,

something like this:

string property =
CmsHttpContext.Current.Channel.CustomProperties["LOGO"].Value;

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------


"bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
news:58BDC5BB-E52B-48E5-ACC8-702469156024@microsoft.com...
>I am new to CMS. I have been assigned to a half finished project, and have
> not been involved from the beginning. I would like to change the
> Header.ascx
> file which includes a LOGO image in the upperleft corner, to dynamically
> grab
> the correct image based on which CHANNEL the visitor is browsing. I am
> digging through 3 different MCMS books, and online tech docs and forums,
> but
> cannot figure out this seemingly easy task. The site is done in C#, i am
> used to VB, but making my way through it.
> I have assigned custom properties to each channel with a name "LOGO" and a
> value "channelname.jpg". I am sure there is a method of Getting the
> Channel
> Name and displaying the image based on the property for that channel.
> Can someone please point me in the right direction using CMS?
> Seems so easy, but this product has so many options.
>
> Thanks in advance.
>



bhprogrammer8

2005-10-24, 10:39 am

Thank you for clearing that up for me. Just to be sure:

If my ImageControl is named ImageLogo then at Page Load, I will have

this.Imagelogo.ImageUrl =
CmsHttpContext.Current.Channel.CustomProperties["logo"].Value;

Is this correct?

Thanks so much.
B
"Stefan [MSFT]" wrote:

> Hi,
>
> something like this:
>
> string property =
> CmsHttpContext.Current.Channel.CustomProperties["LOGO"].Value;
>
> Cheers,
> Stefan
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
> New to MCMS?
> Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
> ----------------------
>
>
> "bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
> news:58BDC5BB-E52B-48E5-ACC8-702469156024@microsoft.com...
>
>
>

Stefan [MSFT]

2005-10-24, 3:28 pm

Hi,

If your custom property only contains the name of the image and not the
complete URL you need to add the path in front of it.
If the custom property holds the URL the code below will be correct.

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------


"bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
news:CF99E7B2-53D2-496D-B929-792E9D83F857@microsoft.com...[vbcol=seagreen]
> Thank you for clearing that up for me. Just to be sure:
>
> If my ImageControl is named ImageLogo then at Page Load, I will have
>
> this.Imagelogo.ImageUrl =
> CmsHttpContext.Current.Channel.CustomProperties["logo"].Value;
>
> Is this correct?
>
> Thanks so much.
> B
> "Stefan [MSFT]" wrote:
>


bhprogrammer8

2005-10-24, 3:28 pm

Thank you Stefan for your help. I am still struggling with this simple job.

Here is my code

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
CmsHttpContext CMSContext = CmsHttpContext.Current;
ChannelCollection colRootChannels = CMSContext.RootChannel.Channels;
this.StartChannel = "MahoningWeb";
FindStartChannel(colRootChannels);
this.Imagelogo.ImageUrl = "http://localhost:2363/mahoningweb/images/" +
CmsHttpContext.Current.Channel.CustomProperties["logo"].Value;

but when I browse, I just get an EMPTY Box where the image should be. Is
there something else CMS related I need to do besides the custom property
setting? A resource or something?
Right Clicking the image in browser gives me NOT AVAILBLE.

Please point me in the right direction.
B



I am not getting any errors but when i view the page in my browser, I get

"Stefan [MSFT]" wrote:

> Hi,
>
> If your custom property only contains the name of the image and not the
> complete URL you need to add the path in front of it.
> If the custom property holds the URL the code below will be correct.
>
> Cheers,
> Stefan
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
> New to MCMS?
> Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
> ----------------------
>
>
> "bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
> news:CF99E7B2-53D2-496D-B929-792E9D83F857@microsoft.com...
>
>
>

Stefan [MSFT]

2005-10-24, 3:36 pm

Hi,

what do you mean with "empty box"?

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------


"bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
news:296721A9-8B14-4623-92B6-6779F27B6EC2@microsoft.com...[vbcol=seagreen]
> Thank you Stefan for your help. I am still struggling with this simple
> job.
>
> Here is my code
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> CmsHttpContext CMSContext = CmsHttpContext.Current;
> ChannelCollection colRootChannels = CMSContext.RootChannel.Channels;
> this.StartChannel = "MahoningWeb";
> FindStartChannel(colRootChannels);
> this.Imagelogo.ImageUrl = "http://localhost:2363/mahoningweb/images/" +
> CmsHttpContext.Current.Channel.CustomProperties["logo"].Value;
>
> but when I browse, I just get an EMPTY Box where the image should be. Is
> there something else CMS related I need to do besides the custom property
> setting? A resource or something?
> Right Clicking the image in browser gives me NOT AVAILBLE.
>
> Please point me in the right direction.
> B
>
>
>
> I am not getting any errors but when i view the page in my browser, I get
>
> "Stefan [MSFT]" wrote:
>


bhprogrammer8

2005-10-25, 7:48 am

Stefan,
My apologies for being so vague. I am referring to a place on the page
where an image is supposed to be. Normally if you refer to an image that
doesn't exist, a web page will show a Red "x" box and you can still see the
image's path if you look at the properties of it. In my case, I just see a
small "blank-transparent-blank-box" area where the image SHOULD show up. And
the properties just say NOT AVAILABLE, so I know it isn't getting the correct
path. The image exists in the path I have programmed, and the Custom
Property exists for each channel as I have explained before.

I am wondering if I need to be BINDING the image DATA somehow. If so, what
is the correct CMS statement to bind to properties data?

Thanks,
Beth

"Stefan [MSFT]" wrote:

> Hi,
>
> what do you mean with "empty box"?
>
> Cheers,
> Stefan
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
> New to MCMS?
> Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
> ----------------------
>
>
> "bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
> news:296721A9-8B14-4623-92B6-6779F27B6EC2@microsoft.com...
>
>
>

Stefan [MSFT]

2005-10-25, 7:48 am

Hi Beth,

please use view source in IE for to get the rendered html and then verify
the URL for the image in the html code.
Is it as expected?
If yes, enter this URL in IE. Does it show the image now?

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------


"bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
news:63DCECC0-8098-493A-914F-5988B884E7C4@microsoft.com...[vbcol=seagreen]
> Stefan,
> My apologies for being so vague. I am referring to a place on the page
> where an image is supposed to be. Normally if you refer to an image that
> doesn't exist, a web page will show a Red "x" box and you can still see
> the
> image's path if you look at the properties of it. In my case, I just see
> a
> small "blank-transparent-blank-box" area where the image SHOULD show up.
> And
> the properties just say NOT AVAILABLE, so I know it isn't getting the
> correct
> path. The image exists in the path I have programmed, and the Custom
> Property exists for each channel as I have explained before.
>
> I am wondering if I need to be BINDING the image DATA somehow. If so,
> what
> is the correct CMS statement to bind to properties data?
>
> Thanks,
> Beth
>
> "Stefan [MSFT]" wrote:
>


bhprogrammer8

2005-10-26, 8:49 pm

Stefan,

I have looked at the rendered html and found this piece where the image
should show up. <img id="Header21_ImageLogo" alt="" border="0" /> Header2
is the name of the control file, and ImageLogo is the name of the image
control on the page. Again, here is the code on the page...

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
CmsHttpContext CMSContext = CmsHttpContext.Current;
ChannelCollection colRootChannels = CMSContext.RootChannel.Channels;
this.StartChannel = "MahoningWeb";
FindStartChannel(colRootChannels);
this.ImageLogo.ImageUrl =
CmsHttpContext.Current.Channel.CustomProperties["Logo"].Value;



"Stefan [MSFT]" wrote:

> Hi Beth,
>
> please use view source in IE for to get the rendered html and then verify
> the URL for the image in the html code.
> Is it as expected?
> If yes, enter this URL in IE. Does it show the image now?
>
> Cheers,
> Stefan
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
> New to MCMS?
> Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
> ----------------------
>
>
> "bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
> news:63DCECC0-8098-493A-914F-5988B884E7C4@microsoft.com...
>
>
>

bhprogrammer8

2005-10-26, 8:49 pm

Stefan,

Im sorry...the code below is incorrect, i do have the full path in the
script. >

private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> CmsHttpContext CMSContext = CmsHttpContext.Current;
> ChannelCollection colRootChannels = CMSContext.RootChannel.Channels;
> this.StartChannel = "MahoningWeb";
> FindStartChannel(colRootChannels);
> this.ImageLogo.ImageUrl =
> "http://localhost:2363/mahoningweb/images/" + CmsHttpContext.Current.Channel.CustomProperties["Logo"].Value;


"bhprogrammer8" wrote:
[vbcol=seagreen]
> Stefan,
>
> I have looked at the rendered html and found this piece where the image
> should show up. <img id="Header21_ImageLogo" alt="" border="0" /> Header2
> is the name of the control file, and ImageLogo is the name of the image
> control on the page. Again, here is the code on the page...
>
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> CmsHttpContext CMSContext = CmsHttpContext.Current;
> ChannelCollection colRootChannels = CMSContext.RootChannel.Channels;
> this.StartChannel = "MahoningWeb";
> FindStartChannel(colRootChannels);
> this.ImageLogo.ImageUrl =
> CmsHttpContext.Current.Channel.CustomProperties["Logo"].Value;
>
>
>
> "Stefan [MSFT]" wrote:
>
Stefan [MSFT]

2005-10-26, 8:49 pm

Hi,

no idea.
you should post this to an ASP.NET related newsgroup as this is not a MCMS
related problem.

Cheers,
Stefan

--
This posting is provided "AS IS" with no warranties, and confers no rights

New to MCMS?
Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
----------------------


"bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
news:5D7B60E9-AF3B-45AD-90D7-C4E7F5593DCA@microsoft.com...[vbcol=seagreen]
> Stefan,
>
> Im sorry...the code below is incorrect, i do have the full path in the
> script. >
>
> private void Page_Load(object sender, System.EventArgs e)
>
> "bhprogrammer8" wrote:
>


bhprogrammer8

2005-10-26, 8:49 pm

Stefan,

you can't believe what the problem is. After running through the page in
debug I found that this code was missing in the page. Don't ask me how it
got removed, but I put it back in, and the image changes now depending on
channel. Thank you so much for your time, and I apologize for wasting any of
it. I learn so much from this forum...it is always my first stop!

private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);

}

Best to you,
Beth

"Stefan [MSFT]" wrote:

> Hi,
>
> no idea.
> you should post this to an ASP.NET related newsgroup as this is not a MCMS
> related problem.
>
> Cheers,
> Stefan
>
> --
> This posting is provided "AS IS" with no warranties, and confers no rights
>
> New to MCMS?
> Check out this book: Building Websites Using MCMS: http://tinyurl.com/6zj44
> ----------------------
>
>
> "bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> wrote in message
> news:5D7B60E9-AF3B-45AD-90D7-C4E7F5593DCA@microsoft.com...
>
>
>

bhprogrammer8

2005-11-11, 5:58 pm

Stefan,

This worked great to get an image that exists in a directory. but how do I
make it get a resource item? I can get my image
(http://localhost:2363/NR/rdonlyres/...dgeInAutumn.jpg) so I know it's there.

I am not sure of the correct method, or syntax here. have tried a couple
things. Something is wrong obviously, but not sure how to fix. Can you
point me in the right direction?

ResourceGallery gallery = CmsHttpContext.Current.Searches.GetByPath
("/Resources/MahoningWeb") as ResourceGallery;
ResourceCollection myCollection = gallery.Resources;
foreach (Resource rs in myCollection)
{
this.ImgHome1.ImageUrl =
CmsHttpContext.Current.Searches.GetByPath("/Resources/MahoningWeb") + rs.Name;

}


Thanks again.
Beth
"bhprogrammer8" wrote:
[vbcol=seagreen]
> Thank you for clearing that up for me. Just to be sure:
>
> If my ImageControl is named ImageLogo then at Page Load, I will have
>
> this.Imagelogo.ImageUrl =
> CmsHttpContext.Current.Channel.CustomProperties["logo"].Value;
>
> Is this correct?
>
> Thanks so much.
> B
> "Stefan [MSFT]" wrote:
>
Stefan [MSFT]

2005-11-13, 5:51 pm

Hi Beth,

actually the code below is strange as you are assigning multiple URLs to
only one image URL.
That does not make sense.
You would need multiple Image objects.

Any way to just retrieve the Url use the following:

ResourceGallery gallery = CmsHttpContext.Current.Searches.GetByPath
("/Resources/MahoningWeb") as ResourceGallery;
ResourceCollection myCollection = gallery.Resources;
foreach (Resource rs in myCollection)
{
string url = rs.Url;
}

Cheers,
Stefan


"bhprogrammer8" <bhprogrammer8@discussions.microsoft.com> schrieb im
Newsbeitrag news:A267996B-B6FB-4A67-A601-2B6F067B6DD4@microsoft.com...[vbcol=seagreen]
> Stefan,
>
> This worked great to get an image that exists in a directory. but how do I
> make it get a resource item? I can get my image
> (http://localhost:2363/NR/rdonlyres/...dgeInAutumn.jpg)
> so I know it's there.
>
> I am not sure of the correct method, or syntax here. have tried a couple
> things. Something is wrong obviously, but not sure how to fix. Can you
> point me in the right direction?
>
> ResourceGallery gallery = CmsHttpContext.Current.Searches.GetByPath
> ("/Resources/MahoningWeb") as ResourceGallery;
> ResourceCollection myCollection = gallery.Resources;
> foreach (Resource rs in myCollection)
> {
> this.ImgHome1.ImageUrl =
> CmsHttpContext.Current.Searches.GetByPath("/Resources/MahoningWeb") +
> rs.Name;
>
> }
>
>
> Thanks again.
> Beth
> "bhprogrammer8" wrote:
>


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com