Monday, March 26, 2012

Please Help - How to do Content Gathering!

ok...here goes...

I need to be pointed in some direction on how this can be done using C#.

Lets say that there is a link for a tab delimited .txt file, or a excel spreedsheet with information that i want to get from one site and populate my database off of that information. But i want to be able to make my webapp smart enough to be able to go get this information in some kind of intervals I want (i.e. --> weekly, monthly, every 3 months...)

Can someone please point me in the right direction as to where I can find how to do this...

thanks in advance.If this has to happen on a regular basis - thus not request-based - ASP.NET is likely not the platform to use. Well, it's the platform to use when creating the web app, but not the technology to gather the content. Instead, there are quite some ways to do this:
1. Create a Windows application to gather content and schedule it using at.exe or the Windows Scheduling in the Control Panel.
2. Create a background Windows Service that can do the gathering behind the scenes.
3. (Advanced) Create a SQL Server Notification Services app that accepts incoming inputs from various sources and - as a delivery - inserts the new retrieved data in the database.
Aye create a service to query your remote server every (X) [x = your interval].
Then have it bring your stream back and parse through it. What are you writing this in c# or vb. You do know depending on what your doing with spreadsheets you may need a copy of excel on your server?
I got a little code that basically works. my problem is that the site i am gathering the information from has sessions on it. so if i just put in the link to the site's file i'll will tell me that the session has expired or that there was a problem with the page. Here is the code I have.

and yes, excel and all the goodies are on the server already.


private void Page_Load(object sender, System.EventArgs e)
{
// it works when the open read command is pointed to the actual file.
System.Net.WebClient Client = new WebClient();
Stream strm = Client.OpenRead("http://www.whatever.com");
StreamReader sr = new StreamReader(strm);

string line;

if (strm != null)
{
do
{
line = sr.ReadLine();
ListBox1.Items.Add(line);
}
while (line !=null);
strm.Close();
}
else
{
lblStatus.ForeColor = Color.Red;
lblStatus.Text = "Something went wrong";
}

Stream strm2 = Client.OpenRead("http://www.whatever.com.aspx?format=excel&prefix=");
StreamReader sr2 = new StreamReader(strm2);
line = string.Empty;

if (strm2 != null)
{
do
{
line = sr2.ReadLine();
ListBox2.Items.Add(line);
lblStatus.Text = line;
}
while (line !=null);
strm2.Close();
}
else
{
lblStatus.ForeColor = Color.Red;
lblStatus.Text = "Something went wrong";
}

}

0 comments:

Post a Comment