C# download file from web using URL and xpath [closed] - c#

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'd like to download the daily photo from this site but i can't use the JPEG's URL because it changes everyday.
Is there any way to download object from site using the page URL and XPath? I tried to find some method in WebClient but with no luck.

An example of my comment with HTML Agility Pack :
WebClient client = new WebClient();
string resource = client.DownloadString("http://photography.nationalgeographic.com/photography/photo-of-the-day/");
HtmlAgilityPack.HtmlDocument html = new HtmlAgilityPack.HtmlDocument();
html.LoadHtml(resource);
var imgDiv = html.DocumentNode.SelectSingleNode("//*[contains(#class,'primary_photo')]");
var imgSrc = imgDiv.SelectSingleNode("//img/#src");
string relativePath = imgSrc.GetAttributeValue("src", "");

Related

Writing to file takes too long [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 4 months ago.
Improve this question
I've got an API where I accept a stream representing an image (usually about ~3mb) and I write this stream into a file. When I test this locally with postman, writing the stream into the file takes about ~20ms. However, when deploying this to production this process takes around 1000ms.
Guid guid = Guid.NewGuid();
string input = InputPathWithExtension(guid);
string output = OutputPathWithExtension(guid);
using FileStream file = File.OpenWrite(input);
await stream.CopyToAsync(file);
await stream.DisposeAsync();
await file.DisposeAsync();

How do I convert an html web page into image using C# [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
How to convert a dynamic link which is a html web page into an Image format. Remember the link is dynamic which contains html content in string format. I have tried a lot of ways like reading the html content using converting to base64 first then visa versa.
var htmlToImageConv = new HtmlToImageConverter();
byte[] jpegBytes = htmlToImageConv.GenerateImage(html, ImageFormat.Jpeg); System.Drawing.Image image; using (System.IO.MemoryStream ms = new System.IO.MemoryStream(strOg))
{
image = System.Drawing.Image.FromStream(ms); string path = Server.MapPath("~/images/");
}
I have tried this code in c# for converting html webpage to image.
You can use a headless browser to render the html and then take a snapshot.
Have a look at PuppeteerSHarp: https://github.com/kblok/puppeteer-sharp
You could use Selenium to render the page and save a screenshot as a png image.
Add the following packages to your project:
Selenium.WebDriver
Selenium.Chrome.WebDriver
Use the following code to save a screenshot:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var driver = new ChromeDriver();
driver.Navigate().GoToUrl("http://google.com");
Screenshot ss = ((ITakesScreenshot)driver).GetScreenshot();
ss.SaveAsFile("screenshot.png");
}
}
}
That what you need is a conversation from a html containing string to an image, which is already discussed in the answers of this Question.

Convert MVC 4 View To Pdf using Itextsharp [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am trying to Convert a MVC 4 View to a PDF. I have no idea where to start, after searching google i found ItextSharp and have been playing around with it.
My View is fairly Simple it has a Map and a Table. i would like to just call an action in the controller and have it print my web page.
Any Advice would be greatly Appreciated
You can use Rotativa
public ActionResult TestViewWithModel(string id)
{
var model = new TestViewModel {DocTitle = id, DocContent = "This is a test"};
return new ViewAsPdf(model);
}
public ActionResult PrintIndex()
{
return new ActionAsPdf("Index", new { name = "Giorgio" }) { FileName = "Test.pdf" };
}
It uses wkhtmltopdf under the hood.
wkhtmltopdf and wkhtmltoimage are open source (LGPLv3) command line
tools to render HTML into PDF and various image formats using the QT
Webkit rendering engine. These run entirely "headless" and do not
require a display or display service.

Post videos to twitter [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I got success to post photos to Twitter. But how do i post videos to Twitter using my C# application?. For posting pictures i used Tweetsharp. Can we use Tweetsharp's SendTweetWithMediaOptions to share video? if yes How?
This is sample i used to share picture to twitter
Bitmap img = new Bitmap(Server.MapPath(#"~/Images/Special/" + Convert.ToInt32(offerId) + "/" + specialOffer.Picture));
MemoryStream ms = new MemoryStream();
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Seek(0, SeekOrigin.Begin);
Dictionary<string, Stream> images = new Dictionary<string, Stream> { { "mypicture", ms } };
var tweet = tweetservice.SendTweetWithMedia(new SendTweetWithMediaOptions { Status = urlTextToShare, Images = images });
and what i need is something like below image
You cannot upload videos to Twitter. If you read their documentation, it says:
Supported image formats are PNG, JPG and GIF, including animated GIFs of up to 3MB
You choices are either to upload an animated GIF or include a URL to a video (such as YouTube / Vimeo)

How to send url with parameters from windows phone 8 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I want to get 2 parametrs from windows phone 8 to php index file , with get or post method
any solutions?
WebClient webClient = new WebClient();
webClient.DownloadStringCompleted += (s, e) =>
{
};
webClient.DownloadStringAsync(new Uri(String.Format("http://example.com?par1={0}&par2={1}", "param1", "param2"), UriKind.RelativeOrAbsolute));

Categories

Resources