Thursday, March 29, 2012

Offline Content Development using ASP.Net 2.0

Hi,

I am currently involved in developing an e-magazine with asp.net 2.0 (C#) and sql server 2000.

One of my requirement is that i want to make available the e-magazine content to the user in offline too.

how to make our website available offline. what kind of coding or component or technology to be used.

I need a detailed implementation or samples to make my e-magazine available offline. I am googling around a

week but i found nothing fruitful.. so pls help me to resolve this...

Thanks in advance...

karthik

To preserve the asp.net content for the readers to view offline, you would need to require the readers have IIS setup on their local machine to run the .net app. Depending on your demographic, this seems like a pretty hefty requirement to push onto users who aren't .net developers.

My suggestion would be to create a pdf or plain html version (one that doesn't depend on any server side technologies) to make available to users that wish to view it offline.


I think you probably have dynamically generated content through SQL. Yeah in order to make your standalone html work, you can create your site through asp.net. Then use wget or some other type of website downloader to grab the content into simple html format and package that.

There is a bit 'hardocre' solution, but you could generate html pages in the file system.
Just the way you write text files, you can write html documents, whith all the formatting and such u might need... anyway, it's a lot of work, you would be addinh a whole new 'reporting' output. But for sure this will work, and requires nothing from customers... maybe just click a link to the "view static html" version... I've done simmilar things in the past for MUST DO requests from customers

regards,
Mauro


Thanks for ur suggestions. Is there any samples available that...

thanks mauro_net. I need more detailed info for that .. if any resources or samples or tutorials available for that

please inform me...

thks

with regards...

nkYes


Ok, I will assume, for a second that html files we'll generate have a fairly simple layout.

Basic steps involved are (details later)
1. Get your data from he database or wherever u have your data.
I will assume for this example you have a table of newsitems [newsitem_id | newsitem_title | newsitem_name ]
So you query the db and get "all" the proper niewsitems, not just 1 by newsitem_id, as you would do in a dynamic frontend.

2. For each row, open a new text file (you'll see examples below), give the file a name dynamically created like "content_35.html" (where 35 is the item's id). With the file created, write the html content inside. Close the file

3. After you populated all the files, you might also want to create an extra html page t odisplay a menu or index or something. Even more, you could use some component out there to generate a zip with all the htmls so they can download and see offline "for real"

I will prepare some codew and write back. w8 a few moments

Here's the code to do what u want (simples scenario ever)
Stick out tongue entry point is a Page_load and it includes all webapp's assemblies for I has VS opened in a webapp project andthat was the fastest. please dont complain about thtat...

using System;

using System.Data;

using System.Configuration;

using System.Collections;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.IO;

publicpartialclassDefault2 : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

GetDataAndWriteThemAll();

}

publicvoid GetDataAndWriteThemAll()

{

//get data from db

//myDataset = select * from tblNewsItems

//for each row

//WriteFile(myDataset("newsitem_title"), myDataset("newsitem_id"), myDataset("newsitem_content"))

WriteFile("testpage","16897","this is the <b>html formatted</b> content!");

WriteFile("one more","32683","oh yeah, i love writing text files to disk!");

}

publicvoid WriteFile(string page_title,string page_id,string page_content)

{

//file will be created on the fly

TextWriter tw =newStreamWriter("c:\\newsitem_"+page_id+".html");

// write a line of text to the file

tw.WriteLine("<html>"); //common html elements...

tw.WriteLine("<head>");

tw.WriteLine("<title>");

tw.WriteLine(page_title); //let's be nice and add a <title>

tw.WriteLine("</title>");

tw.WriteLine("</head>");

tw.WriteLine("<body>");

tw.WriteLine("<h1>" + page_title +"</h1>");//big page title

tw.WriteLine("<hr>"); //a horizontal bar, why not?

tw.WriteLine(page_content); // large html from the database, for instance

tw.WriteLine("<hr>");

tw.WriteLine(page_title); //let's be nice and add a <title>

tw.WriteLine("Last updated: " +DateTime.Now.ToString());

tw.WriteLine("</html>");

// close the stream

tw.Close();

}

}

GO TO C:\ AND SEE THE GENERATED FILES

what I did when I had this requirement was to have multiple templates.
My templates where normal html pages with some special markups for replacement, for instance
<PAGE_TITLE> or <PAGE_CONTENT> so basically the app has to load the desired template, replace the strings "<PAGE_TITLE>" or "<PAGE_CONTENT>" with whatever it was supposed to replace, and the use the resulting html (template with replaced tags) to write the file to disk

The good thing about using tempates is that u can have a complex html formatting and not worries about hardocding it inside the app creating the files.

Some other problems you might face are
- But my pages aer much more complex than a text from the db --> hey! you will have to clone the logic generating your real 'online' pages and make sure you can generate a simmilar html
- I need to rebuild a complete website, with loads of buttons, menues, links all over the place --> how simmilar to the original site it is, will depend on how much money you're getting for it.

If the output is just too complex to be generated this way, you might consider using a desktop tool for dowloading the whole thing to your pc and expose it as a zip in your site... there's nothing else to say abou that

I hope this helps,
Please tell me what u think and if u have more queries


Thanks a lot Mauro for your efforts. What's the problem with my e-magazine is, all the pages in it are stored as

images in a web server. and to show a page i have to load it from the server by specifying the url like http://address/12345.jpg.

The db contains the url only. My magazines looks very similar to the samples available in http://www.nxtbook.com/samples/magazines/

website. Pls check this out and give me a solution. My magazine is purely developed using asp.net 2.0 and no flash matters included.

it also contains the menu features as u could see in the samples of the above mentioned web site.

To change this to offline what i must do? hope u'll come around with a better solution that helps me...

thanks a lot...

karthik


Ok, in order to give you further advice, i must understand exactly what do u mean by "content available offline"

What exactly is going to be offline? you want an offline user to write a url in browser and still be able to see the content?

I would give the users the possibility to download (1, or all) magazines in zip format...

Please be more clear on the requirement


The user is allowed to download the specific magazine he needs. The downloaded file may be an

exe or zip. the pages of the magazine could be stored as JPEG files or BLOB object in Database on client machine for off line viewing.

(which is better?) . In fact the whole application is to be downloaded but with the specific magazine content only. The off line content is nothing

but the pages and application and all the pages are jpeg files.

hope you will get it clear. if not pls dont hesitate to reply me

with regards......

karthik



Ok, I could point you to a way to resitribute your site between your customers, even with just 'some' images in it, but i really don't think that is a good idea.... I mean, why to download a complete webapp and run it locally to read a magazine?
And if that is the case, can 't you make a desktop app?the desktop app could do all the work for the custmer, including downloading only the allowed content when the user has connection and if there's some weird presentation engine/presentation logic (which i think it is), it can handle t as well. It could download also xml data for implementing some kind of search engine, etc, and still be in some way a simple application. I really do not think having users running your web app locally is a good idea... neither safe or userfriendly!! what kind of users do u have? is the magazine presentation logic that complex? can it be a desktop app instead of a web app? Is there a flash or dhtml magazine-viewer? And also... why would u store the images as blobs on the client? is there a reson for it? that's pretty twisted the way i see it, unless there's an specific reason or requirement...

So what i suggest is a workaround.
If you have no option, if there is an specific requirement for users to work with your own app locally... the yeah, all the IIS setup and stuff mencioned avobe will be required.

regards,
Mauro


Hi mauro, i can't get in contact for the past few days because of my work schedule...

I need ur suggestions for my offline client development with the use of Microsoft's

Smart Client Offline Application Block. I have downloaded the required dlls but i dont

know the proper way of implementing it. If you have any ideas about it, pls inform me..

thanks in advance..

karthik


WOW It is the first time in my life i hear about such thing... it is unbeliveable how many weird solutions are out there... I'm sorry I can help you but for what i've just seen in msdn, that's exactly what you need!
So far, I wonder about this quote "Smart clients are applications that are native to a user's PC and are also network-aware" ... I thought a common desktop app could do so... actually... I did it for years. I don't really understand what's so speccial about it, but i guess this is just a set of components which help u simplify conectivity-related development.

Ok, gotta go (I am plenty of duties myself.... and I have a new baby component that is making me so proud...! soon to be posted on codeproject (it was about time)

I will take another look later on about this technology. In the meantime, keep posting, the solution is around the corner.
Regards,
Mauro


Hi,

One of my application needs a web service that can download images from the webserver.

The images are stored in the webserver and it can be accessed by giving its url like http://.../image001.jpg

Can any one give me a sample code for the web service. I have written an application using WebClient Class.

but it displayes the download dialog box with Open, save, Close buttons. I just need to download the images when the user

clicks the Download button. A progress can be displayed.

Note : sometimes A bulk of 50 to 100 images are to downloaded in a single click.

thanks in advance..

with regards..

yenkay



0 comments:

Post a Comment