I want to access Internet Explorer Download List
I tried to access History with UrlHistoryWrapperClass but that does not give me path of the downloaded file.
I need Filename, FilePath and URL aswell.
My problem is accessing View Downloads list of internet explorer. If anyone achieved that before, i appriicate the help.
Thanks in advance.
I do not believe you are able to get this information from the history (unless there is an exploit I'm not aware of). The best you can do is go through the history and if needed, you can trigger a webclient to re-download the file. Attached is a generic example for Internet Explorer for at least traversing the history:
public class InternetExplorer
{
// List of URL objects
public List<URL> URLs { get; set; }
public IEnumerable<URL> GetHistory()
{
// Initiate main object
UrlHistoryWrapperClass urlhistory = new UrlHistoryWrapperClass();
// Enumerate URLs in History
UrlHistoryWrapperClass.STATURLEnumerator enumerator =
urlhistory.GetEnumerator();
// Iterate through the enumeration
while (enumerator.MoveNext())
{
// Obtain URL and Title
string url = enumerator.Current.URL.Replace('\'', ' ');
// In the title, eliminate single quotes to avoid confusion
string title = string.IsNullOrEmpty(enumerator.Current.Title)
? enumerator.Current.Title.Replace('\'', ' ') : "";
// Create new entry
URL U = new URL(url, title, "Internet Explorer");
// Add entry to list
URLs.Add(U);
}
// Optional
enumerator.Reset();
// Clear URL History
urlhistory.ClearHistory();
return URLs;
}
Related
I have a URL with multiple paths. For example:
https://stackoverflow.com/questions/120250
I want to grab the URLS entire path and save it, then I want to call the URL later to duplicate the URL with all the paths. URL path is dynamic.
So for I have attempted this
public Shared DuplicateTheChromeBrowser()
{
String selectLinkOpeninNewTab = (Keys.Alt + "d" + Keys.Enter);
var SavedURL = Driver.Instance.Url();
SavedURL.SendKeys(selectLinkOpeninNewTab);
return this;
}
Try this out. It saves the url of the page you go to or are on, then uses JS to create a new tab and send the URL from the original page to the new tab. Initbrowser() is my method for initiating an instance, so it its not necessarily part of the solution.
public Shared DuplicateTheChromeBrowser()
{
//Initiate Browser Instance(this is my method, initiate how you did in our code which isnt visible in your question)
IWebDriver driver = InitBrowser("chrome");
//Go to page
driver.Url = "https://stackoverflow.com/questions/120250?params=testparam";
//Save Current URL
var SavedUrl = driver.Url;
//Uses JS to open new tab
((IJavaScriptExecutor)driver).ExecuteScript("window.open();");
driver.SwitchTo().Window(driver.WindowHandles.Last());
//Changes Url of new tab to saved URL including param
driver.Url = SavedUrl;
}
I'm using C# and Xamarin forms to create a phone app that (when a button is pressed) will pull specific html data from a website in and save it into a text file (that the program can read from again later). I started with the tutorial in this video: https://www.youtube.com/watch?v=zvp7wvbyceo if you want to see what I started out with, and here's the code I have so far made using this video https://www.youtube.com/watch?v=wwPx8QJn9Kk, in the the "AboutViewModel.cs" file created in the video:
Image link because this is a new account i guess and i cant embed images or something
Paste of the code itself (but the image gives you a better look at everything):
private Task WebScraper()
{
HtmlAgilityPack.HtmlWeb web = new HtmlAgilityPack.HtmlWeb();
HtmlAgilityPack.HtmlDocument doc = web.Load("https://www.flightview.com/airport/DAB-Daytona_Beach-FL/");
foreach (var item in doc.DocumentNode.SelectNodes("//td[#class='c1']"))
{
var itemstring = item;
File.WriteAllText("AirportData.txt", itemstring);
}
return Task.CompletedTask;
}
public ICommand OpenWebCommand { get; }
public ICommand WebScraperCommand { get; }
}
}
The only error i'm getting right now is "Cannot convert 'HtmlAgilityPack.HtmlNode' to 'string'" Which i'm working on fixing but I don't think this is the best solution so anything you have is useful. Thanks :)
HtmlNode is an object, not a simple string. You probably want to use the OuterHtml property, but consult the docs to see if that is the right fit for your use case
string output = string.Empty;
foreach (var item in doc.DocumentNode.SelectNodes("//td[#class='c1']"))
{
output += item.OuterHtml;
}
File.WriteAllText("AirportData.txt", output);
note that you need to specify a path to a writable folder, the root folder of the app is not writable. See https://learn.microsoft.com/en-us/xamarin/xamarin-forms/data-cloud/data/files?tabs=windows
I am trying to invalidate CloudFront objects in C#/.NET and gettign the following exception:
Your request contains one or more invalid invalidation paths.
My Function:
public bool InvalidateFiles(string[] arrayofpaths)
{
for (int i = 0; i < arrayofpaths.Length; i++)
{
arrayofpaths[i] = Uri.EscapeUriString(arrayofpaths[i]);
}
try
{
Amazon.CloudFront.AmazonCloudFrontClient oClient = new Amazon.CloudFront.AmazonCloudFrontClient(MY_AWS_ACCESS_KEY_ID, MY_AWS_SECRET_KEY, Amazon.RegionEndpoint.USEast1);
CreateInvalidationRequest oRequest = new CreateInvalidationRequest();
oRequest.DistributionId = ConfigurationManager.AppSettings["CloudFrontDistributionId"];
oRequest.InvalidationBatch = new InvalidationBatch
{
CallerReference = DateTime.Now.Ticks.ToString(),
Paths = new Paths
{
Items = arrayofpaths.ToList<string>(),
Quantity = arrayofpaths.Length
}
};
CreateInvalidationResponse oResponse = oClient.CreateInvalidation(oRequest);
oClient.Dispose();
}
catch
{
return false;
}
return true;
}
The array passed to the function contains a single Url like so:
images/temp_image.jpg
The image exists in the S3 bucket and loaded in the browser in the CloudFront URL.
What am I doing wrong?
You invalidation file paths need a / at the front of the string.
If you are in doubt, you can log onto AWS Management, go to Cloudfront, select the distribution you are trying to invalidate files from, select Distribution setting and go to the Invalidations tab.
You can then create validations manually, which allows you to check that your paths are correct.
When you send invalidation request to some object in CloudFront, you still can see your picture in the browser in the CloudFront URL even when invalidation completed, because invalidation does not delete object from S3 bucket and with new request to this image from you browser CloudFront again cached these URl to images/temp_image.jpg in edge locations.
Invalidation of object will be seen, when you update image with the same name.
Your Invalidation function is correct.
Have you tried adding the forward slash at the beginning of the path? (/images/temp_image.jpg)
I've been able to integrate some scheduled web service calls into my Umbraco site that uses the response from the web service to update some of the content on my site. I can now handle text and some various other content but my main query is how should I deal with images that are delivered from the web service in byte[] format?
For a little context, the site I am developing uses web service calls to retreive the details of a product which users of our desktop software have created on their machine. Each of these products is pulled via a web service call into my Umbraco site and created as an individual product page under the parent node of products.
Products > Product
Each product has several properties such as an ID, a name, notes and a collection of images. Once I have called my web service I am creating these pages using the following code:
//Construct Service Request
svc = new StaticDataWebServiceSoapClient();
var response = svc.GetProducts(ref compressionSoapHeader,ref managedUserHeader);
//Umbraco Content Services
int rootID = 1117;
IContentService cs = ApplicationContext.Current.Services.ContentService;
var remove = cs.GetChildren(rootID).Where(x => x.ContentType.Alias == "product");
foreach (var child in remove)
{
cs.Delete(child);
}
foreach(var product in response){
var item = cs.CreateContent(product.ContinentName, rootID, "product");
//Set the properties using the SetValue method, passing in the alias of the property and the value to assign to it
item.SetValue("continentId", product.Id);
item.SetValue("continentName", product.ProductName);
item.SetValue("continentNotes", product.Notes);
foreach (var image in product.Images)
{
??? destination.SetValue("ProductImages", image._Image); ???
image.Caption;
image.FileName;
image.ImageId;
image.KeywordID;
}
cs.SaveAndPublishWithStatus(item);
}
As you can see from the code, each product has several images associated with it that I would also like to pull into the site and associate with the product page that is being created. How would I go about doing this? Would I need to use the Media Service and a specific datatype or would this structure fit easily into a multiple media picker?
You may find it easiest to loop through the images once you've retrieved them and create a new Media item for each of them, and then associate them with the product using a property based on something like the Multiple Media Picker datatype as you noted.
Because this data type stores it's values as a comma separated list of id's you could use something like the following:
// Setup
IContentService cs = ApplicationContext.Current.Services.ContentService;
var mediaService = ApplicationContext.Current.Services.MediaService;
int mediaRootId = 1111; // Replace with the id of your media parent folder
// Replace the image looping logic with the following:
// MultiMediaPicker stores it's values as a commma separated string of ids.
string imageIds = string.Empty;
foreach (var image in product.Images)
{
var fileName = image.FileName; // Assumes no path information, just the file name
var ext = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower();
if (!UmbracoConfig.For.UmbracoSettings().Content.DisallowedUploadFiles.Contains(ext))
{
var mediaType = Constants.Conventions.MediaTypes.File;
if (UmbracoConfig.For.UmbracoSettings().Content.ImageFileTypes.Contains(ext))
mediaType = Constants.Conventions.MediaTypes.Image;
var f = mediaService.CreateMedia(fileName, mediaRootId, mediaType);
// Assumes the image._Image is a Stream - you may have to do some extra work here...
f.SetValue(Constants.Conventions.Media.File, fileName, (Stream)image._Image); // Real magic happens here.
mediaService.Save(f);
imageIds += (imageIds.Length > 0 ? "," : "") + f.Id;
}
}
// Get the relevant property on the new item and save the image list to it.
var imagesProp = item.Properties.Where(p => p.Alias == "productImages").FirstOrDefault();
imagesProp.Value = imageIds;
Note - I haven't tested this code out, so ymmv.
I'm trying to allow users to post videos on my site by supplying only the URL. Right now I'm able to allow YouTube videos by just parsing the URL and obtaining the ID, and then inserting that ID into their given "embed" code and putting that on the page.
This limits me to only YouTube videos however, what I'm looking to do is something similar to facebook where you can put in the YouTube "Share" URL OR the url of the page directly, or any other video url, and it loads the video into their player.
Any idea how they do this? or any other comparable way to just show a video based just on a URL? Keep in mind that youtube videos (which would probably be most popular anyway) don't give the video url, but the url to the video on the YouTube page (which is why their embed code is needed with just the ID).
Hopefully this made sense, and I hope somebody might be able to offer me some advice on where to look!
Thanks guys.
I would suggest adding support for OpenGraph attributes, which are common among content services which work to enable other sites to embed their content. The information on the pages will be contained in their <meta> tags, which means you would have to load the URL via something like the HtmlAgilityPack:
var doc = new HtmlDocument();
doc.Load(webClient.OpenRead(url)); // not exactly production quality
var openGraph = new Dictionary<string, string>();
foreach (var meta in doc.DocumentNode.SelectNodes("//meta"))
{
var property = meta["property"];
var content = meta["content"];
if (property != null && property.Value.StartsWith("og:"))
{
openGraph[property.Value]
= content != null ? content.Value : String.Empty;
}
}
// Supported by: YouTube, Vimeo, CollegeHumor, etc
if (openGraph.ContainsKey("og:video"))
{
// 1. Get the MIME Type
string mime;
if (!openGraph.TryGetValue("og:video:type", out mime))
{
mime = "application/x-shockwave-flash"; // should error
}
// 2. Get width/height
string _w, _h;
if (!openGraph.TryGetValue("og:video:width", out _w)
|| !openGraph.TryGetValue("og:video:height", out _h))
{
_w = _h = "300"; // probably an error :)
}
int w = Int32.Parse(_w), h = Int32.Parse(_h);
Console.WriteLine(
"<embed src=\"{0}\" type=\"{1}\" width=\"{2}\" height=\"{3}\" />",
openGraph["og:video"],
mime,
w,
h);
}