I do have an problem in C# that is
Suppose there is one website's link....www.xyz.comand suppose there are 25 links on the website's home page.
Now i want that using C# and asp.net i do have an String array suppose LinkArray[n] and TabArray[n] {string array} and i want that there should be a program which
can list all the links in the array as follows.
suppose links are :
Home
etc
Now i want that in two arrays it should be stored as
TabArray[2]= {Home,Contact}
LinkArray[2]={xyz.com/home.html,xyz.com/contact.html}
Likewise i want that i can get listed all the links details in of any web page.
Please suggest me some code/ guide tutorials
Thanks
You could use sharp-query or Html Agility Pack to parse HTML. Here's an example with sharp-query:
using System;
using XCSS3SE;
class Program
{
static void Main()
{
var sq = new SharpQuery("http://stackoverflow.com");
foreach (var el in sq.Find("a[href]"))
{
Console.WriteLine("{0} : {1}", el.InnerText, el.Attributes["href"].Value);
}
}
}
Related
I have run into a road block developing my Codename One app. One of my classes in my project parses 3 specific html "td" elements from a website and saves the text to a string where I then input that text data into a Codename One multibutton. I originally used jSoup for this operation but soon realized that Codename One doesn't support 3rd party jar files so I used this method as shown below.
public void showOilPrice() {
if (current != null) {
current.show();
return;
}
WebBrowser b = new WebBrowser() {
#Override
public void onLoad(String url) {
BrowserComponent c = (BrowserComponent) this.getInternal();
JavascriptContext ctx = new JavascriptContext(c);
String wtiLast = (String) ctx.get("document.getElementById('pair_8849').childNodes[4].innerText");
String wtiPrev = (String) ctx.get("document.getElementById('pair_8849').childNodes[5].innerText");
String wtiChange = (String) ctx.get("document.getElementById('pair_8849').childNodes[8].innerText");
Form op = new Form("Oil Prices", new BoxLayout(BoxLayout.Y_AXIS));
MultiButton wti = new MultiButton("West Texas Intermediate");
Image icon = null;
Image emblem = null;
wti.setEmblem(emblem);
wti.setTextLine2("Current Price: " + wtiLast);
wti.setTextLine3("Previous: " + wtiPrev);
wti.setTextLine4("Change: " + wtiChange);
op.add(wti);
op.show();
}
};
b.setURL("https://sslcomrates.forexprostools.com/index.php?force_lang=1&pairs_ids=8833;8849;954867;8988;8861;8862;&header-text-color=%23FFFFFF&curr-name-color=%230059b0&inner-text-color=%23000000&green-text-color=%232A8215&green-background=%23B7F4C2&red-text-color=%23DC0001&red-background=%23FFE2E2&inner-border-color=%23CBCBCB&border-color=%23cbcbcb&bg1=%23F6F6F6&bg2=%23ffffff&open=show&last_update=show");
}
This method works in the simulator (and gives a "depreciated API" warning), but does not run when I submit my build online after signing. I have imported the parse4cn1 and cn1JSON libraries and have gone through a series of obstacles but I still receive a build error when I submit. I want to start fresh and use an alternative method if one exists. Is there a way that I can rewrite this segment of code without having to use these libraries? Maybe by using the XMLParser class?
The deprecation is for the WebBrowser class. You can use BrowserComponent directly so WebBrowser is redundant in this case.
I used XMLParser for this use case in the past. It should work with HTML as it was originally designed to show HTML.
It might also be possible to port JSoup to Codename One although I'm not sure about the scope of effort involved.
It's very possible that onLoad isn't invoked for a site you don't actually see rendered so the question is what specifically failed on the device?
I have been trying to use SiteMapProvider from NuGet and make it link to a database in order to get all the links for a sidebar and breadcrumb, so far I don't find any tutorial, and I keep getting stuck using the information to the xml file, I am sure that I have to create a class, but I don't seem to find any tutorial on how to do this, or how to correctly make the call to this class, is there a tutorial or any website that contain this information? I have been trying to do what is included in here:
https://github.com/maartenba/MvcSiteMapProvider/wiki/Dynamic-sitemaps
But I don't know how to define the dynamicNodeProvider, any help? Sorry if it's some what vague what I am asking.. I have tried to search but I haven't find any information..
EDIT:
I was able to load information using :
[MvcSiteMapNode(Title = "HOLDCREATEREPORT", ParentKey = "Home", Key = "CreateReport")]
on each, class, but I am more interested in doing this using a unique class that loads all nodes, I have tried so far to change the sitemap xml to the following code:
navigation itself has the following code:
public class navigation : DynamicNodeProviderBase
{
public override IEnumerable<DynamicNode> GetDynamicNodeCollection(ISiteMapNode node)
{
for (int i = 0; i < 20; i++)
{
DynamicNode dynamicnode = new DynamicNode();
dynamicnode.Title = "test"+ i.ToString();
dynamicnode.ParentKey = "Home";
dynamicnode.RouteValues.Add("test" + i.ToString(), "abcdb"+ i.ToString());
yield return dynamicnode;
}
}
}
yet when I run it nothing gets displayed, I am pretty sure I am missing something extremely easy >_>.
Dynamic Node Providers require a definition node. The definition node can either be in XML or as a .NET attribute. It won't be included in the SiteMap, but the nodes that the Dynamic Node Provider create will be.
[MvcSiteMapNode(Title = "Dynamic Nodes", DynamicNodeProvider = "MyNamespace.navigation, MyAssembly")]
Or
<mvcSiteMapNode title="Dynamic Nodes" dynamicNodeProvider="MyNamespace.navigation, MyAssembly">
Scenario : ASP.NET site has a page named ShowDesign.aspx.
ASPX page has lot of controls. I have a DIV tag and I load the images in code behind. DIV is defined something like below in the ASPX.
<div id="pImageHolder" runat="server"></div>
Below is the code behind that loads images.
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
//Loop inside PreviewImages which has lots of images.
foreach (String imgFile in this.PreviewImages)
{
Image pImage = new Image();
pImage.ImageUrl = imgFile; //URL length is longer. Do something.
this.pImageHolder.Controls.Add(pImage);
}
}
Update : Jun 1,2012 -> I have updated this question with more clarity as to what I am trying to do.
In OnInit(), I get the URL of the image (in the above loop). Every image will have unique URL.
Since the URL length of every image is longer, it doesn't display. The solution to this issue seems to be POSTING data to the form. The data that needs to be POSTED will be the URL contents.
The URL contains lot of '&' and I need to submit the contents of each '&' to the form.
Don't know if I need to use AJAX or Jquery here.
I need some help here to achieve the above.
Hope my question is clear. If not, please let me know.
According to latest comments, this question history and at the end you want post data to another url and get response html. Try this (I snipped your original url from previous question since is really big):
string strangeUrl = "http://example.com/is/m//company1/Rec-Sc-105-QL2?setAttr.safe={visible=false}&setAttr.insertedTextPlaceholder={visible=false}";
string data = strangeUrl.Substring(strangeUrl.IndexOf("?") + 1);
WebClient wc = new WebClient();
wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
string result = wc.UploadString("www.example.com/addres-for-post.aspx", data);
I am trying to use the jQuery UI autocomplete feature in my web application. What I have set up is a page called SearchPreload.aspx. This page checks for a value (term) to come in along with another parameter. The page validates the values that are incoming, and then it pulls some data from the database and prints out a javascript array (ex: ["item1","item2"]) on the page. Code:
protected void Page_Load(object sender, EventArgs e)
{
string curVal;
string type ="";
if (Request.QueryString["term"] != null)
{
curVal = Request.QueryString["term"].ToString();
curVal = curVal.ToLower();
if (Request.QueryString["Type"] != null)
type = Request.QueryString["Type"].ToString();
SwitchType(type,curVal);
}
}
public string PreLoadStrings(List<string> PreLoadValues, string curVal)
{
StringBuilder sb = new StringBuilder();
if (PreLoadValues.Any())
{
sb.Append("[\"");
foreach (string str in PreLoadValues)
{
if (!string.IsNullOrEmpty(str))
{
if (str.ToLower().Contains(curVal))
sb.Append(str).Append("\",\"");
}
}
sb.Append("\"];");
Response.Write(sb.ToString());
return sb.ToString();
}
}
The db part is working fine and printing out the correct data on the screen of the page if I navigate to it via browser.
The jQuery ui autocomplete is written as follows:
$(".searchBox").autocomplete({
source: "SearchPreload.aspx?Type=rbChoice",
minLength: 1
});
Now if my understanding is correct, every time I type in the search box, it should act as a keypress and fire my source to limit the data correct? When I through a debug statement in SearchPreload.aspx code behind, it appears that the page is not being hit at all.
If I wrap the autocomplete function in a .keypress function, then I get into the search preload page but still I do not get any results. I just want to show the results under the search box just like the default functionality example on the jQuery website. What am I doing wrong?
autocomplete will NOT display suggestions if the JSON returned by the server is invalid. So copy the following URL (or the returned JSON data) and paste it on JSONLint. See if your JSON is valid.
http://yourwebsite.com/path/to/Searchpreload.aspx?Type=rbChoice&term=Something
PS: I do not see that you're calling the PreLoadStrings function. I hope this is normal.
A couple of things to check.
Make sure that the path to the page is correct. If you are at http://mysite.com/subfolder/PageWithAutoComplete.aspx, and your searchpreload.aspx page is in another directory such as http://mysite.com/anotherFolder/searchpreload.aspx the url that you are using as the source would be incorrect, it would need to be
source: "/anotherFolder/Searchpreload.aspx?Type=rbChoice"
One other thing that you could try is to make the method that you are calling a page method on the searchpreload.aspx page. Typically when working with javascript, I try to use page methods to handle ajax reqeusts and send back it's data. More on page methods can be found here: http://www.singingeels.com/Articles/Using_Page_Methods_in_ASPNET_AJAX.aspx
HTH.
there!
I'm working with asp.net 3.5 web-site. And I have such problem:
I have 3 aspx pages, that contain asp:Label control with name "LabelContent" and foreach page I have two resx files, that contain LabelContentResource.Text and LabelContent binds LabelContentResource to , for 2 cultures. Also I have content editing page. On this page admin choses page for edit and in WYSIWG editor I need to load appropriate resorce. Like so:
string pageForLoadName = "links.aspx.de-AT.resx";
string key ="LabelContent.Text";
string resValue= LoadREsource(pageForLoadName ,key );
How can I write LoadREsource fnction?
Thanks!
Something along the lines of
public string LoadResource(string pageForLoadName,string key)
{
return (String)HttpContext.GetGlobalResourceObject(pageForLoadName, key);
}
Also, don't think you need pageForLoadName = "links.aspx.de-AT.resx";
just pageForLoadName = "links.aspx.de-AT";