I am using below code to download my target web site source and extract my required information .
protected void Button1_Click(object sender, EventArgs e)
{
WebClient Client = new WebClient ();
Client.DownloadFile("target page url", " D:/myTextFile.txt");
}
But in some cases in my target web site i need to press a key to load my required information.
For example in this page I should press "More" Button to see full data.
How can i reach this object?
Related
I receive some html data from server, and I try to build a webview to show these data.
Then I need to set some labels to navigate to other page of UWP.
In Windows Phone 8 projects, I can add a label like this to navigate to another page and pass parameters.
But UWP doesn't support it anymore, so how to navigate to another page and pass parameters??
Here is a solution.
1.This is the string that webview will navigate to.
"<html>"+
"<body>"+
"<script type='text/javascript'>" +
"function Click()" +
"{window.external.notify('parameter1+" + "parameter2"+"...");}" +
"</script>" +
"<a href='#' onclick='Click();'>" + "NameOfLabel</a>" +
"</body>"+
"</html>";
2.Webview add a scriptnotify event in your xaml.
<WebView ScriptNotify="webView_ScriptNotify"></WebView>
3.Get parameter from javascript
private async void webView_ScriptNotify(object sender, NotifyEventArgs e)
{
//Get the paramter from javascript
string parameter=e.value;
}
4.One more, there is another wat to pass complicate parameters like a class.
But I can't find this artilce, I will add the url later if I find it.
I am using following code to open share UI. It opens all available share text sharing apps. Is there any way i can filter those share to Messaging and Whatsapp apps?
void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataRequest request = e.Request;
request.Data.Properties.Title = "the title";
request.Data.Properties.Description = "description";
request.Data.Properties.ApplicationName = "Messeging";
request.Data.SetText(shareText);
}
No, this is the expected behaviour and all the apps who can read text will be shown.
I have followed all the steps given in the documentation to register for a push notification from the Parse website. (All the steps in the sense I downloaded the default project and added event handler to handle the incoming toast notification).
ParseClient.Initialize("x0uNa3Q164SVGKbH4mxZJaxWxsuYtslB5tVPj893",
"cXFv9RQAoray9xFdwdcZCHXrrkrM6KNd0WyN194H");
this.Startup += async (sender, args) =>
{
// This optional line tracks statistics around app opens, including push effectiveness:
ParseAnalytics.TrackAppOpens(RootFrame);
// By convention, the empty string is considered a "Broadcast" channel
// Note that we had to add "async" to the definition to use the await keyword
await ParsePush.SubscribeAsync("");
};
ParsePush.ToastNotificationReceived += ParsePushOnToastNotificationReceived;
and the handler
private void ParsePushOnToastNotificationReceived(object sender,
NotificationEventArgs notificationEventArgs)
{
var s = new ShellToast();
s.Content = notificationEventArgs.Collection.Values.First();
s.Title = "My Toast";
s.Show();
}
private async void Application_Launching(object sender, LaunchingEventArgs e)
{
await ParseAnalytics.TrackAppOpenedAsync();
}
When I run the app in the emulator it registers the app and I can verify it in my dashboard. But as soon as I send push notification from the website number of registered devices will be shown as 0 and the app doesnt receive the notification.
One thing to mention is this behavior is not consistent. Sometimes the app does receive the notification. Can anyone mention the reason for this or any other point I am missing?
One thing to note is that ShellToast.Show() should only be used from background task. If you call it when an app is in the foreground, toast won't be shown. http://msdn.microsoft.com/en-US/library/windowsphone/develop/microsoft.phone.shell.shelltoast.show(v=vs.105).aspx
So, be sure your app is not in the foreground when you expect to see toast notification.
Firstly you will be shown toast notification only if the foreground app is not running. If your app is running when you receive push notification you have to do like:
void ParsePushOnToastNotificationReceived(object sender,
NotificationEventArgs notificationEventArgs)
{
Deployment.Current.Dispatcher.BeginInvoke(()=>{
// do anything
MessageBox.Show("got notification");
});
}
If your app is not running the os will handle the notification properly, you dont have to do anything.
I'm looking for a free tool or dlls that I can use to write my own code in .NET to process some web requests.
Let's say I have a URL with some query string parameters similar to http://www.example.com?param=1 and when I use it in a browser several redirects occur and eventually HTML is rendered that has a frameset and a frame's inner html contains a table with data that I need. I want to store this data in the external file in a CSV format. Obviously the data is different depending on the querystring parameter param. Let's say I want to run the application and generate 1000 CSV files for param values from 1 to 1000.
I have good knowledge in .NET, javascript, HTML, but the main problem is how to get the final HTML in the server code.
What I tried is I created a new Form Application, added a webbrowser control and used code like this:
private void FormMain_Shown(object sender, EventArgs e)
{
var param = 1; //test
var url = string.Format(Constants.URL_PATTERN, param);
WebBrowserMain.Navigated += WebBrowserMain_Navigated;
WebBrowserMain.Navigate(url);
}
void WebBrowserMain_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
if (e.Url.OriginalString == Constants.FINAL_URL)
{
var document = WebBrowserMain.Document.Window.Frames[0].Document;
}
}
But unfortunately I receieve unauthorizedaccessexception because probably frame and the document are in different domains. Does anybody has an idea of how to work around this and maybe another brand new approach to implement functionality like this?
Thanks to the Noseratio's comments I managed to do that with the WebBrowser control. Here are some major points that might help others who have similar questions:
1) DocumentCompleted event should be used. For Navigated event body of the document is NULL.
2) Following answer helped a lot: WebBrowserControl: UnauthorizedAccessException when accessing property of a Frame
3) I was not aware about IHTMLWindow2 similar interfaces, for them to work correctly I added references to following COM libs: Microsoft Internet Controls (SHDocVw), Microsoft HTML Object Library (MSHTML).
4) I grabbed the html of the frame with the following code:
void WebBrowserMain_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
if (e.Url.OriginalString == Constants.FINAL_URL)
{
try
{
var doc = (IHTMLDocument2) WebBrowserMain.Document.DomDocument;
var frame = (IHTMLWindow2) doc.frames.item(0);
var document = CrossFrameIE.GetDocumentFromWindow(frame);
var html = document.body.outerHTML;
var dataParser = new DataParser(html);
//my logic here
}
5) For the work with Html, I used the fine HTML Agility Pack that has some pretty good XPath search.
I have a windows phone app that connects to a local IIS Server. It downloads some json data and displays it in a list box. I also have a refresh button on the page. When the page loads everything is correct but pressing the refresh button only returns the same data that was available when the page is loaded. I have checked my web browser with the uri and the updated data shows there correctly. Also If I exit the windows phone app and reload it the data is there. Here is some dumbed down code I am testing with.
On page load:
WebClient download = new WebClient();
download.DownloadStringCompleted += new DownloadStringCompletedEventHandler(download_DownloadStringCompleted);
download.DownloadStringAsync(new Uri("http://sampledata/data"));
void download_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
This works fine and displays a message box with my json string.
On Refresh:
private void Button_Click(object sender, RoutedEventArgs e)
{
WebClient refresh = new WebClient();
refresh.DownloadStringCompleted += new DownloadStringCompletedEventHandler(refresh_DownloadStringCompleted);
refresh.DownloadStringAsync(new Uri("http://sampledata/data"));
}
void refresh_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
MessageBox.Show(e.Result);
}
This displays the same json string that was displayed on page load even though the data has changed. Does anyone have any ideas? Thanks.
try adding a time stamp to the end of the URL. like refresh.DownloadStringAsync(new URI("http://sampledata/data" + DateTime.Now.ToString()));
How much data do You pulling out from server? Try with HttpWebRequest if you need heavy lifting. I also had some issuses with webclient loading and refreshing data. Every change on server comes with big delay...