|
Here[^] is a video on this topic.
|
|
|
|
|
Hello everyone,
I am working on a project and need your help. I have a div having the search results in the form of links or URLs . Now I want to save them in a file. Can anyone guide me that how can I extract and save those links from div to variables or any simple data structures like array or arraylist.
Waiting for quick response!
Thanks in advance.
|
|
|
|
|
|
Parse the div content and look for the a or href tags within that text.
|
|
|
|
|
Thank you for reply. Actually now I am trying t parse div but y code is not working. Here it is :
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(this.Page.MapPath("~/Default2.aspx"));
HtmlNodeCollection bodyNodes = doc.DocumentNode.SelectNodes("//div[@id='wrapper']/a[@href]");
foreach (var node in bodyNodes)
{
string href = node.Attributes["href"].Value;
}
But the selected nodes are empty. May be because it only has content on runtine otherwise its empty. How to get div data on runtime ? Please help.
|
|
|
|
|
First find the div in contentplace holder like this make sure u have an atribute of runat="server" in ur div and controls you want to find.
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ContentPlaceHolder myContent = (ContentPlaceHolder)this.Master.FindControl("ContentPlaceHolder1");
System.Web.UI.Control Testdiv = myContent.FindControl("TestDiv1");
System.Web.UI.Control anchor1 = Testdiv1.FindControl("Your Anchor id");
}
}
}
}
|
|
|
|
|
Thank you for reply. Actually now I am trying t parse div but y code is not working. Here it is :
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(this.Page.MapPath("~/Default2.aspx"));
HtmlNodeCollection bodyNodes = doc.DocumentNode.SelectNodes("//div[@id='wrapper']/a[@href]");
foreach (var node in bodyNodes)
{
string href = node.Attributes["href"].Value;
}
But the selected nodes are empty. May be because it only has content on runtine otherwise its empty. How to get div data on runtime ? Please help.
|
|
|
|
|
Hi,
I m redirecting my abc.aspx page to default page with querystring then after reading querystring i want to redirect it again in abc.aspx page bt m nt getting url wid querystring in default page its showing null,so i want to get url of abc.aspx?id=11 with querystring in default page only...plz help me
-- modified 30-Sep-13 18:37pm.
|
|
|
|
|
Please don't cross post. You've already asked this question here[^].
/ravi
|
|
|
|
|
Does this[^] answer help?
Also, please don't use txtspk in these forums. It's considered rude form.
/ravi
|
|
|
|
|
i hav jst joined wat is txtspk
|
|
|
|
|
DollieBSP wrote: i hav jst joined wat is txtspk
I have just joined, what is text speak.
Use English and use the entire keyboard.
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
DollieBSP wrote: wat is txtspk See this[^] link. Please don't use it - you risk being ignored if you ask questions containing txt spk.
Also, please never TYPE IN ALL CAPS, and don't ask people to "plz gimme code 'cos its urgent". This site is manned by volunteers, most of whom work 10+ hours a day at their day jobs and help out at CodeProject because they want to, not because they have to.
/ravi
|
|
|
|
|
Hello,
I am getting an error when trying to save my XLS to .DBF. The error is: An OLE DB Provider was not specified in the ConnectionString. An example would be, 'Provider=SQLOLEDB;'. I am getting the error at this line of code: var cnn = new OleDbConnection(cnnStr);
var cnnStr = @"Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};DBQ=C:\file.xls;ReadOnly=1;ColNameHeader=False";
var cnn = new OleDbConnection(cnnStr);
var dt = new DataTable();
try
{
cnn.Open();
string sqlConnectionString = "Data Source=Zach-PC;Initial Catalog=master;Integrated Security=True";
var schemaTable = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
if (schemaTable.Rows.Count < worksheetNumber) throw new ArgumentException("The worksheet number provided cannot be found in the spreadsheet");
string sql = String.Format("select * from [{0}]", sqlConnectionString);
var da = new OleDbDataAdapter(sql, cnn);
da.Fill(dt);
}
catch (Exception e)
{
throw e;
}
finally
{
cnn.Close();
}
Any pointers?
Regards,
Glen
|
|
|
|
|
That looks like an ODBC connection string. Try one of the OLEDB Excel connection strings from:
http://www.connectionstrings.com/excel/[^]
For example:
var cnnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\file.xls;Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\"";
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Thanks solved that error, I am getting a different error now tho error: 'DataSource=excelFilePath;InitialCatalog=master;IntegratedSecurity' is not a valid name. Make sure that it does not include invalid characters or punctuation and that it is not too long.
|
|
|
|
|
DataSource is wrong, it should be Data Source : two words.
Veni, vidi, abiit domum
|
|
|
|
|
Okay thanks, same error occurs though with Data Source as two words.
|
|
|
|
|
The rest of the information in that statement does not look like the example that was suggested to you.
Veni, vidi, abiit domum
|
|
|
|
|
Connection strings are provider-specific. The sting you have there uses an Excel file as the "data store" but you are passing SQL-server parameters with InitialCatalog and IntegratedSecurity. Those aren't parameters the "Excel data provider" understands.
|
|
|
|
|
You've opened an OLEDB connection to an Excel spreadsheet, and you're now trying to execute the query:
select * from [Data Source=Zach-PC;Initial Catalog=master;Integrated Security=True]
That's not a valid query. A valid query would look something like:
select * from [SheetName$Range]
Perhaps if you explain what you're trying to achieve, we might be able to help.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am trying to achieve an application that is able to read in an Excel Spreadsheet (.XLS) and be able to convert/save out to a Database file (.DBF).
Regards,
|
|
|
|
|
Start by reading the sheet:
static DataTable LoadExcelSheet(string fileName, int worksheetNumber, bool headers)
{
if (string.IsNullOrEmpty(fileName)) throw new ArgumentNullException("fileName");
if (!File.Exists(fileName)) throw new FileNotFoundException(null, fileName);
var cnnStr = string.Format(
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"Excel 8.0;HDR={1};IMEX=1\"",
fileName,
headers ? "Yes" : "No");
using (var cnn = new OleDbConnection(cnnStr))
{
cnn.Open();
var schemaTable = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
var sheetRow = schemaTable.AsEnumerable()
.Where(row => !((string)row["TABLE_NAME"]).EndsWith("$"))
.Skip(worksheetNumber).FirstOrDefault();
if (sheetRow == null) throw new ArgumentException("The worksheet number provided cannot be found in the spreadsheet");
string sql = string.Format("SELECT * FROM [{0}$]", sheetRow["TABLE_NAME"]);
var da = new OleDbDataAdapter(sql, cnn);
var dt = new DataTable();
da.Fill(dt);
return dt;
}
}
That will give you a DataTable containing the data from the Excel sheet. You'll then need to use a SqlConnection and a SqlDataAdapter to update your SQL database.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
Okay Thanks will try that!
|
|
|
|
|
I am working on a small application that will read sql xml type to C# WPF. Since my database information is changing I need to display the root node name for each sql data type created. I can query the database and display the hyperlinks but unable to open them and get to the root node name. Any suggestions?
|
|
|
|