How to convert image data url into contentid in C#? - c#

In application I used Tinymce editor in which if images inserted then it is stored like below :-
<div>
<img src="D:\My Folder\pic1.jpg" />
<img src="D:\My Folder\pic2.png" />
<img src="D:\My Folder\pic3.gif" />
</div>
I want to replace image url path with content id.
<div>
<img src="cid:{0}" />
<img src="cid:{1}" />
<img src="cid:{2}" />
</div>
is it possible?

Related

ASp.net Webform multiline textbox adds line break on page load automatically

From last one/two weeks i am noticing that any multiline textbox that i am using in asp.net web-form based website adds line-break to textbox automatically.
This has never happened before i ma facing this issue with almost all asp.net webform websites
<textarea name="txtComment" rows="2" cols="20" id="txtComment" tabindex="4" class="comment-box">
</textarea>
I am not sure why this is happening. It gets bad when we update the page & if we dont manually remove line breaks it will keep on adding linebreak to multiline textbox. I am not sure if this issue is due to some windows update or browser. It happens in Firefox & later i noticed same in Chrome?
Not sure why this is happening
Example: Code
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" Rows="3"> Line </asp:TextBox>
</div>
</form>
HTML Rendered Output
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title>
</title></head>
<body>
<form method="post" action="./TESTMultiline.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUJNjQ0NTE4MDYwZGRecdSIl8wWZzLW33b1SXrfQmgMkA==" />
</div>
<div>
<input name="TextBox1" type="text" id="TextBox1" />
<textarea name="TextBox2" rows="3" cols="20" id="TextBox2">
Line </textarea>
</div>
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="F8195D5B" />
<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEdAAN9qVvxr9edjD9ICF1fyY9rESCFkFW/RuhzY1oLb/NUVB2nXP6dhZn6mKtmTGNHd3PbNvMJfATDdpnltdJAG8xg/EABZA==" />
</div></form>
<!-- Visual Studio Browser Link -->
<script type="application/json" id="__browserLink_initializationData">
{"appName":"Firefox","requestId":"b33e31c27a494a9c8d0d82b3f5432ca7"}
</script>
<script type="text/javascript" src="http://localhost:61571/7d590f801da8489ebffe28d952f8f4af/browserLink" async="async"></script>
<!-- End Browser Link -->
</body>
</html>
OUTPUT
The problem is related to the way the TextBox Control is being rendered. Changing the value for controlRenderingCompatibilityVersion in web.config did the trick for me:
controlRenderingCompatibilityVersion=4.5
The information is from the question Extra characters added to multiline textbox, answer from JTapp/jmoreno.
just remove
from this row
<textarea name="TextBox2" rows="3" cols="20" id="TextBox2"> Line </textarea>
Two options:
Remove the space before the "_Line" in your source code: probably an unwonted character is 'hiding' there
Try remove text all together - and adding it in the code behind: TextBox2.Text = "Line";
Edited:
Open Chrome dev tool and check all css/classes/styling that effects this tag

I have an issue in accessing the html elements in ASP.NET

I have linked my html elements with ID to can read it
I can access the asp elements inside the same page in this tag
<script></script>
but I can't access its in the separate code file called"Default.aspx.cs"
also the ordinary html elements can't access its inside <script></script>
rather than the separate code file "Default.aspx.cs"
<%# language="C#" %>
<!DOCTYPE html>
<html>
<head>
<title>A few goals</title>
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script runat="server">
</script>
</head>
<body runat="server" onload="checkConnection">
<div class="container">
<div class="row" style="margin-top:200px;">
<center>
<div class="col-xs-12">
<h3>Authentication Step</h3>
<hr />
<form runat="server">
<input type="text" id="untxt" runat="server" placeholder="Username"/>
<input type="password" id="pwdtxt" runat="server" placeholder="Password"/>
<input type="submit" id="enterbtn" runat="server" value="Enter" />
<br />
<br />
<center><asp:Label ID="errmsg" runat="server">
</asp:Label></center>
<br />
<center><b style="color:darkred;">if account not exist , it will create a new account automaticity</b></center>
</form>
</div>
</center>
</div>
</div>
</body>
</html>
I need easy way to access these elements easily , thanks
You can't just access html tags in your .cs file, even if you add IDs to them, this is only for javascript and css. You can access the elements marked with <asp:.../> or <asp:...></asp> and should contain runat=server.
<asp:Button id="id" text="label" OnClick="sub" runat="server" />
This button you should be able to access throgh ID id in your Default.cs. I suggest you to take a look at this documentation.

how to save image using <input type = "file"> into oracle database using asp.net C#

I could display an oracle database blob image in an <img> tag using the handler but all what I want to know how to insert the uploaded image using input of type file
and I have this form enclosing (BaladiaInfo.aspx is the name of the page)
<form id="form1" runat="server" action="BaladiaInfo.aspx" method="post" enctype="multipart/form-data"> </form>
this is my input and img partitions
<img src="Handler2.ashx" id="BlobImg" />
<input type="file" name="FileUploaad" id="Browse" s/>
and I have a button at the bottom of the page that updates the page controls values plus the new browsed image
<div id="SaveButtons" class="actions" style="text-align: center;">
<asp:Button ID="Button1" runat="server" Text="save" Width="100" Style="font-size: 20px"
OnClick="Button1_Click1" />
I want the code that enables me to update the blob image in database

Populate javascript gallery from code behind

I have the following gallery -
<div class="content">
<div id="myGallery">
<div class="imageElement">
<h3>IMAGE 1</h3>
<p></p>
<img src="image1.jpg" class="full" />
<img src="image.jpg" class="thumbnail" />
</div>
<div class="imageElement">
<h3>IMAGE 2</h3>
<p></p>
<img src="image2.jpg" class="full" />
<img src="image2.jpg" class="thumbnail" />
</div>
</div>
</div>
This works fine when the images are hard coded like above, getting read from a folder.
However I wish to populate the gallery from the code behind with images I do not have stored but from a URL. Like - www.fooBar.com/image1.png and once this is retrieved then push it into the gallery?
I have tried the following -
Setting <div id="myGallery" id="testHtml">
then in the code behind -
testHtml.innerHTML = // built html with image src = url etc
However this just rendered the image without putting it into the gallery itself.
No shortage of ways to skin this cat, but one way is to create a literal like this:
<div id="myGallery">
<asp:Literal id="ltrImages" runat="server" />
</div>
Then in your codebehind:
var imageElement #"<div class=""imageElement"">
<h3>{0}</h3>
<p></p>
<img src=""{1}"" class=""full"" />
<img src=""{1}"" class=""thumbnail"" />
</div>";
StringBuilder sb = new StringBuilder();
//Presuming you have your images in some kind of collection called "images"
for(var image in images){
sb.Append(String.Format(imageElement, image.title, image.src));
}
ltrImages.Text = sb.ToString();
<asp:Panel> has a property named Controls which you could use in order to add your <div class="imageElement"> containers, images, headers and more.
See here for how to add an item: http://msdn.microsoft.com/en-us/library/kyt0fzt1(v=vs.110).aspx
See here how to create a custom tag: http://msdn.microsoft.com/en-us/library/5f8y80ez(v=vs.110).aspx

Why my image slider not working on other pages in a subfolder using masterpage

Hi been creating a web application using VS 2010 using C#.the problem i am having is that i have added image slider on the master page. but when i run the application it does not show the slider on the pages which are in a subfolder but shows the image slider in a file which is in the root.
for the image slider i have used jquery
this is how i have coded the images on masterpage
<div id="slide-holder">
<div id="slide-runner">
<img id="slide-img-1" src="~/Styles/images/nature-photo1.png" class="slide" alt="" />
<img id="slide-img-2" src="~/Styles/images/nature-photo1.png" class="slide" alt="" />
<img id="slide-img-3" src="~/Styles/images/nature-photo2.png" class="slide" alt="" />
<img id="slide-img-4" src="~/Styles/images/nature-photo3.png" class="slide" alt="" />
<img id="slide-img-5" src="~/Styles/images/nature-photo4.png" class="slide" alt="" />
<img id="slide-img-6" src="~/Styles/images/nature-photo4.png" class="slide" alt="" />
<img id="slide-img-7" src="~/Styles/images/nature-photo6.png" class="slide" alt="" />
<div id="slide-controls">
<p id="slide-client" class="text"><strong>post: </strong><span></span></p>
<p id="slide-desc" class="text"></p>
<p id="slide-nav"></p>
</div>
</div>
it not showing up on the pages located in subfolders but working with pages located in the root
You have to make sure that all of the src and urls are being resolved successfully. For this, use the ResolveUrl() function to successfully resolve all of your images regardless of the location. Also, if you are using Css, you have to make sure the images inside the css are being resolved correctly:
Example:
<img id="slide-img-2" src='<%= ResolveUrl("~/Styles/images/nature-photo1.png") %>' class="slide" alt="" />
Good luck!

Categories