When I try to append the image name onto the end of the <%$ Resources:LocalizedText, MyKey %> the server doesn't build the path at all.
This is what I'm doing and it's not working:
<img id="Img2" runat="server" src="<%$ Resources:LocalizedText, ImagesPath %>feature_LED.jpg" />
Is there any way to append?
this will work instead
src="<%= Resources.LocalizedText.ImagePath %>
Related
I have a web.config key :
<add key="IMGSRC" value="http://localhost" />
I want to use the value of this key along with the path of the image concatenated to in an aspx page. I'm aware that I can get to root folder by simply saying "../ImagesFolder" , but my website has parent path disabled because of security concerns. So now I need to work around it.
I need something like this (Here are a few things I tried after looking up the internet and which did not work.):
1) <img id="Img19" runat="server" alt="Admin" src='<%#ConfigurationSettings.AppSettings["IMGSCR"] %>' />
2) <img id="Img19" runat="server" alt="Admin" src='<%#ConfigurationSettings.AppSettings["IMGSCR"] + "/ImagesFolder/img.jpeg" %> ' />
3)
<img id="Img19" runat="server" alt="Admin" src="<%#ConfigurationSettings.AppSettings["IMGSCR"] %> " + "/ImagesFolder/img.jpeg" />
Also I tried this:
I declared a variable Path on Page_Load
Path = System.Configuration.ConfigurationManager.AppSettings["RootforIMG"].ToString();
and then on aspx page I tried using it as
<img id="Img19" runat="server" alt="Admin" src="<%=Path %> " + "/ImagesFolder/img.jpeg" /> but this as well is no good.
Can you try something like below?
<img id="Img19" runat="server" alt="Admin" src='<%= GetImageSource()%>' />
In code behind
public string GetImageSource()
{
return ConfigurationManager.AppSettings["IMGSCR"] + "/ImagesFolder/img.jpeg";
}
The relative path of images should work:
Relative path can be as per your page location i.e: '../IMages/img.jpg' or 'images/img.jpg'
try this :
<img id="Img19" runat="server" alt="Admin" src='ImagesFolder/img.jpeg' />
For controls with runat="server" attribute you do not need any special code to map a path relative to web site root:
<img id="Img19" runat="server" alt="Admin" src"~/ImagesFolder/img.jpeg" />
The path ~/ImagesFolder/img.jpeg will be resolved replacing ~ with the root folder of your web-site.
If to resolve path you need some kind of logic (for example you need to call a function) then you can use this:
<img src'<%= ResolveImageName() %>' />
Do not forget that URL must be proper encoded.
I have stored file in my server, clients can download files via my page Home.aspx by clicking on an anchor, but i want to edit the original filename before launching download. How can i do it using an ASP.NET HttpHandler. Thanks in advance.
This is my anchor code:
<% if (document.Path != null) { %>
<a id="downloadLink" runat="server" style="margin: 5px" href="<%# CONTENT_DIRECTORY_ROOT + document.Path %>">
<%= LanguageManager.GetValue("LABEL_DOWNLOAD") %></a>
<% } %>
Try the RewritePath(newUrl) method
HttpContext.Current.RewritePath(sUrl)
Or you could use
HttpContext.Current.Server.Transfer(sUrl)
I added HyperLink control in my page. When I enter "http://www.google.com", It is opening in new window (good) and pointing google.
1. When I enter "www.google.com", It is opening in new window, but Url is "http://mysite.com/www.google.com". Why this is happing? How to should point to www.google.com
<a href= '<%# Eval("ConferenceUrl") %>' runat ="server" id="ConferenceUrl"
target="_blank"> <%# Eval("ConferenceUrl")%> </a>
You need http:// in the url, I believe.
The <%# Eval("ConferenceUrl") %> needs to have the http:// prefix. Either change your data or add it to the href attribute.
<%# Eval("ConferenceUrl")%>
you have to add http:// in the beginning of href
If I use the following code without runat="server" the input's src works fine and I see the image coming through.
<div><input id="testButton" type="image" src="<%=TestButtonImageUrl %>" onserverclick="RedirectTest" /></div>
url is https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image
But if I put the runat="server" in, for some reason, I get this for the url:
<div><input id="testButton" type="image" src="<%=TestButtonImageUrl %>" onserverclick="RedirectTest" runat="server" /></div>
url is http://localhost/%3C%=lButtonImageUrl%20%%3E
You cannot use the <%= %> syntax with server controls (including standard HTML elements with runat="server"). You have two choices:
Access the control in the code behind (as an HtmlInputControl) and assign the src attribute using the Attributes property: imageControl.Attributes["src"] = value;
Assign the attribute using the databinding syntax (src="<%# %>") and call imageControl.DataBind() from the code behind
Maybe I'm missing something. But runat server tag does not support code expression.
When you add runat="server to that html tag, Asp.Net converts it from string to HtmlControl - in this case of type HtmlInputImage. You can see this happen by adding:
<%= testButton.GetType() %>
Then the only thing you need to do is set the Src-property, which, contrary to other comments, you CAN do in inline aspx - no need for a code-behind file:
<%
testButton.Src = "/content/logo.png";
%>
<input id="testButton" type="image" runat="server" src="" onserverclick="RedirectTest" />
You need to set the Src-property BEFORE the actual input, which is a bit non-intuitive, the reason is that the code is run at render-time, so if the setting of Src-property is after the control, it is too late.
if jQuery is an option than you could try this:
<script type="text/javascript">
$(function() { $('#<%=testButton.ClientID %>').attr('src', '<%=TestButtonImageUrl %>'); });
</script>
...
<div><input id="testButton" runat="server" type="image" onserverclick="RedirectTest" /></div>
Update:
Another option is to create a HttpHandler with processing like this
public void ProcessRequest(HttpContext context)
{
var testButtonImageUrl = "https://fpdbs.paypal.com/dynamicimageweb?cmd=_dynamic-image";
context.Response.Redirect(testButtonImageUrl);
}
add in web.config path to handle image.img or whatever and update aspx
<div><input id="testButton" runat="server" type="image" src="image.img" onserverclick="RedirectTest" /></div>
I'm trying to write a custom rendering template for use in the DisplayForm of a list whose fields include Title, HeaderImageUrl, Body. I've got the following so far:
<SharePoint:RenderingTemplate ID="NewsListForm" runat="server">
<Template>
<h1><SharePoint:FieldValue FieldName="Title" runat="server"/></h1>
<div>
<p>
<SharePoint:UrlField FieldName="HeaderImageUrl" runat="server"></SharePoint:UrlField>
<SharePoint:RichTextField FieldName="Body" runat="server" />
</p>
</div>
</Template>
</SharePoint:RenderingTemplate>
The HeaderImageUrl field is configured to be an Image URL, but when I use the UrlField control, it renders a link.
I was thinking there might be a way to grab field values and put them in attributes, so something like this:
<asp:Image ImageUrl="<% FieldValue["HeaderImageUrl"] %>" runat="server"/>
If this kind of thing isn't possible, then is there another control in Microsoft.SharePoint.WebControls that would render an image from a URL?
All the examples I've seen of calling a URL field to be displayed as an image have been through C# code. Which is quite annoying since most of web part bits can be written without using C# code. You might also need to go down that road here... perhaps a custom field control or user control.
Even if your code above did get the value for HeaderImageUrl, it wouldn't work as Url values are (confusingly):
[the actual url specified][some wierd delimeter string][the description field of the url (usually the actual url again if your don't specify it)]
So you would need to split the string with te delimeter values and use the [0] (the first) as what you inject into your image url.
Please do post if you find a way to do this without writing C# code.
p.s. Have you considered using a DataFormWebPart which has a xsl section in which you might be able to do extractly what you need?!
Example: You can stick the following syntax into any aspx / ascx file:
<%# Register tagprefix="SharePoint" namespace="Microsoft.SharePoint.WebControls" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register tagprefix="WebPartPages" namespace="Microsoft.SharePoint.WebPartPages" assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%# Register Tagprefix="PublishingWebControls" Namespace="Microsoft.SharePoint.Publishing.WebControls" Assembly="Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<WebPartPages:DataFormWebPart runat="server" IsIncluded="True" FrameType="None"
NoDefaultStyle="TRUE" ViewFlag="0" Title="My List Display"
Default="FALSE" ID="dfwp_MyListDisplay"
DisplayName="My List Display">
<DataSources>
<SharePoint:SPDataSource runat="server" DataSourceMode="List" UseInternalName="true"
selectcommand='<View><Query><Where><Eq><FieldRef Name="Category"/><Value Type="Text">Header</Value></Eq></Where></Query></View>' id="Utility_x0020_Navigation1"><SelectParameters><WebPartPages:DataFormParameter Name="ListName" ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="My List Display"/>
<asp:Parameter Name="ListName" DefaultValue="LIST NAME" />
<asp:Parameter Name="WebUrl" DefaultValue="<% $SPUrl:~SiteCollection/ %>" />
</SelectParameters>
</SharePoint:SPDataSource>
</DataSources>
<ParameterBindings>
<ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
<ParameterBinding Name="PageURL" Location="ServerVariable(URL)" DefaultValue=""/>
<ParameterBinding Name="SiteUrl" Location="ServerVariable(SERVER_NAME)" DefaultValue=""/>
</ParameterBindings>
<datafields>#Title,Title;#URL,URL;#Category,Category;#Parent_x0020_item,Parent_x0020_item;#Sort_x0020_Order,Sort Order;#ID,ID;#ContentType,Content Type;#Modified,Modified;#Created,Created;#Author,Created By;#Editor,Modified By;#_UIVersionString,Version;#Attachments,Attachments;#File_x0020_Type,File Type;#FileLeafRef,Name (for use in forms);#FileDirRef,Path;#FSObjType,Item Type;#_HasCopyDestinations,Has Copy Destinations;#_CopySource,Copy Source;#ContentTypeId,Content Type ID;#_ModerationStatus,Approval Status;#_UIVersion,UI Version;#Created_x0020_Date,Created;#FileRef,URL Path;</datafields>
<xsl>
YOUR XSLT HERE
</xsl>
</WebPartPages:DataFormWebPart>
The following code will get you the url of an imagefield:
SPListItem item = GetItem();
string imagefieldhtml = item["HeaderImageUrl"].ToString();
ImageFieldValue imagefield = new ImageFieldValue(imagefieldhtml);
var url = imagefield.ImageUrl;
So maybe altering your to something like this will help you, or maybe help you out atleast...?
<asp:Image ImageUrl="<% (ImageFieldValue ["HeaderImageUrl"]).ImageUrl %>" runat="server"/>
Unable to test it atm (no environment) but I am quite sure I did this before.
Try these:
<SharePoint:FieldValue FieldName="HeaderImageUrl" runat="server"/>
or:
<img src="<SharePoint:FieldValue FieldName="HeaderImageUrl" runat="server"/>" />
I'll check back on this one and do an actual test by monday if those didn't work and you still need help.
Turns out that my problem was simply that I didn't have that image column set up to render as an image, rather than as a link. The builtin Microsoft.SharePoint.UrlField control worked just fine, as it turned out.