is it possible to grab an image that is embedded in a div via C# and attach it to an email?
I've got the code for attaching and sending images via email, I just don't know how to get it to grab the specific item out of the div and email it.
The image varies with a previous user selection so I can't just apply a static address of an image.
any ideas?
You need to grab image from inbound email?
Read more about MIME format: all images in email message are encriped in base64 format in MIME message. To grab your image you need to parse your emailmessage, read base64 string, wich encript your image, and decoding this string like this:
var byties = Convert.FromBase64String(Body)
I would look at using the microsoft html control, read the document and use the DOM to get the url of the image, download it using the http and then attach it to your email
for reference
How to download the image
Reading the Dom from visual studio
Use HtmlAgilityPack and HttpWebRequest.
Related
I am using the QR Coder library in C# to generate QR codes that will go to a URL with a Token in the Query String.
https://github.com/codebude/QRCoder
Currently, I can Print Preview all the QR Codes, but without a Token showing beneath it.
I need to display a string below the QR Code image with a Token Code when I click on the Print Preview button. This will fetch all the QR Code images and show them on the Print Preview window.
The Print Preview button will fetch all the Tokens generated, append them to a link and finally generate the base64 string for the QR Image that is sent to a JavaScript Print method.
I am using Print JS: https://printjs.crabbly.com/
Below is my JavaScript method below with the following code (Multiple Image Mode):
function printAllQRCodesForProduct(base64, printwidth) {
printJS({ printable: **base64**, type: 'image', imageStyle: 'width:' + printwidth + '%;margin-
bottom:10px; float:left; margin-right:10px;' });
}
It does not seem that Print JS can allow you to have multiple image captions. If this was the case, that would work. Perhaps I can modify the Print JS code or perhaps is it possible to somehow take the generated Base64 image QR code and append a string with the Token text just below it without having to render the image on a Canvas tag and then re-saving it as a Base64 string? Can all this be done on the Code-Behind in C#?
So in summary, is it possible to modify a base64 generated image with another image and combine them, or is there a way to add text and get a new base64 image string?
I see that it is possible to add text to a generated Bitmap in C#.
Found the answer on this post: c# write text on bitmap
I need to display files in a HTML page in an object tag.
I use C# MVC4 to send the file. In my code, I set the "Content-Type" and "Content-Disposition" headers.
When I set the Content-Type to something Chrome dosen't know, it will download the file, regardless of the "Content-Disposition" header.
HTML:
<div>
<object data="http://localhost/UncHelper?path=secrectPath\file.dwg"></object></div>
C#:
public override void ExecuteResult(ControllerContext context)
{
context.RequestContext.HttpContext.Response.AddHeader("Content-Type", _contentType);
context.RequestContext.HttpContext.Response.AddHeader("Content-Disposition", "inline; filename=\"" + _fileName + "\"");
context.HttpContext.Response.WriteFile(_uncPath);
context.HttpContext.Response.End();
}
When I try to display a pdf file (_contentType = application/pdf) everything is fine.
But when I try to display a .dwg (_contentType = application/dwg) Chrome will download the file. How can I prevent this?
(I don't want to set a HTML status of 203 based on the browser or anything like that.)
Thanks!
This is not possible, and is also a slight misunderstanding on your part i think. For a browser to be able to display a file, it first has to be downloaded.. This goes for all file types. For instance, if you were displaying an image of image/jpeg, with the disposition set to inline, the browser still downloads the image, and then displays it inline, instead of asking the user where he/she would like to save it. If the browser has no knowledge of how to display the file, this is not an option, and will default to the only other option, which is to ask the user where to save it.
I am trying to login a website by POST method through HttpWebRequest. In the beginning, i create a portrait page to let user to enter username and password and access the web page. I successfully to Post the data and get the HTML content from the website. Finally I using the Webrowser.NavigateTostring method to display the website in the webBrowser I create.
Problem 1: Inside the webBrowser, I can not do any action in the website. In the normal webBrowser, after successfully login I can do any action such as go to event forum..but what i face is I can't navigate to event forum or any forum.
Problem 2: Inside the webBrowser, the image will not showing eg, user picture, product picture. I also trying to use IsolatedStorage method to show the HTML content but it also non work.
What I confusing is wheather the Webrowser.NavigateTostring method is a way to asynchronous operation to the website in internet? and what I doing wrong? or I looking for wrong direction?
Any help would be appreciated. Thank you.
Unfortunately, Set-Cookie is one of the HTTP headers that are not supported.
This way will suffer from these problems as if you load the HTML using WebBrowser.NavigateToString or from Isolated Storage none of the relative links to images, scripts or CSS will work. Also it is impossible to pass any Cookies from HttpWebRequest to the WebBrowser
The way to do this is to use the WebBrowser control itself to do the POST. There is a overload of the WebBrowser.Navigate method as documented on MSDN here. That will allow you to POST data to your URL.
// generate your form data based on the data you got from your "portrait page"
// and get the bytes from that.
// (e.g. write your post data to a MemoryStream as UTF8 and get its bytes)
byte[] formBytes = ...
// write HTTP headers here, including the type of data you're posting, e.g.:
string headers = "Content-Type: application/x-www-form-urlencoded"
+ Environment.NewLine;
Uri uri = ... // where you want the POST data to be sent
this.webBrowser.Navigate(uri, formBytes, headers);
That way your web browser will be properly initialized and your cookies, images, scripts and CSS should all work.
I'd like to pre-visualize an image in a image box before save it in a directory.
How can i do this, i use a checkbox to see if the user wants to pre-visualize or not because i dont find another way to do this without a checkbox.
I use file upload to upload the image.
string serverFileName = "";
serverFileName = Path.GetFileName(Upload.PostedFile.FileName);
Upload.PostedFile.SaveAs(MapPath("~/fotosPerfil/") + serverFileName);
i use this piece of code to save the image.
I think this post is exactly what you need to implement. Check out Ivan's solution.
Yes, indeed you can read the path selected by the user and display the image in an <img> tag, all client-side prior to uploading.
I have a javascript function that get base64 string then I need to pass this value to a silverlight object within my page to render the base64 as jpeg image
Now I use AJAX to build the image and rerender it on the page but it take alot of time I believe that with silverlight it won't take that much of time
So any resources on this issue?
You can just set the image src to the base64 string, both on tags and in CSS. So you don't have to convert the base64 string, you can just render it in place. This will give you a faster user experience.
Replace the underscores in the following examples with your base64 string:
<img src="data:image/png;base64,______________">
Or, using CSS:
background-image: url(data:image/png;base64,_____________);
If you want to send something from JavaScript to Silverlight (1) to process it (2), and then maybe back from Silverlight to JavaScript (3), check out the below links. When I say "process it", this probably means saving the image and sending back an image URL. But if you want to display it using Silverlight, this is of course unnecessary.
JavaScript/Silverlight Interop (includes passing JS parameter to Silverlight)
C#: Base64 string to Bitmap
Pass parameters from Silverlight to JavaScript