Specific click counting mechanism in ASP and C# - c#

What is a good way to display a click counter in HTML, if you are using a .aspx file that links to a .cs file which obtains headings from a SQL server without using an external text file to keep track by reading in and out? I'd really rather not use javascript because I want to associate it with a specific ID.

you'll need some sort of persistent storage to keep track over time. So either a text file, or recording each click to a database table.

Related

Auto Fill Webform through Word doc in Asp.net

hey i'm working on project in which I have webform which includes some editfields. I don't want to enter the data manually into that editfield. what I want is to extract data from a word document and fill that editfields. But the catch is, through which MS doc I fill the editfield?
Suppose We have a bunch of lectures uploaded on some page. so what should I do to retrieve the data from a particular document?
Is it necessary to open the MS-doc file first?
or I should download the file first?
If I goes with option 1 when should I have to use some library? what opens the file within browser, retrieve the data and the a pop-up message appears "the data has been retrieved now you can close the file". and next I can fill the form with that data.
or should I goes with the 2 Option when an individual hit the download button then the file will be stored into the local machine. how can I keep the track that which ms-file is downloaded or stored into the local machine?and is it necessary to open that file for retrieving the data again?
These are my point of views that how I can implement that module. So I need your suggestions? Is this the right way to achieve this goal or should I follow the other path? and which libraries are required to achieve this task or any tutorial similar to this problem ?
Thanks in Advance
I would suggest considering a third option: since the Word document files exist on the server, the cleanest place to pre-populate a form would be by extracting data from the document while it is on the server and filling in the form's fields before sending it down to the user in a codebehind. Trying to extract data on the client side from a recently-downloaded file via an application other than the browser seems ripe for kludgy-ness. Articles such as http://support.microsoft.com/kb/257757 should help get you started in the right direction.
For extracting data from ms word document using free .net word component and fill data to webform,
extract data,
Document doc = new Document();
doc.LoadFromFile("YouDocOrDocx.Docx");
string content = doc.GetText();

how to save chat transcripts in sql server database and retrieve it on another page with formatting?

I am Working on a chat application in which i used a multiline textbox to show messages. Now First of all i want to give different colors in my chat. Our user message should be in different color and another user message should be in different color.
Second thing i want that i want to save transcripts of chat conversation with formatting so that user can see it anytime.
I don't know how to save transcript to database with formatting. So i am stucked here.
I am using C# and Sql server database.
How can i do that?
If you break down your problem, then it would make it much easier to solve it.
Instead of taking text from textbox. Have you thought about maybe storing it as xml?
If you use xml, you can use xslt to generate a nice looking html (but it depends on how you want to use it later)
You have different options how you store it in the database
plain text
xml
blob
Please do your research and then ask specific questions if you get stuck.

Efficient way to upload files

I have a aspx webpage where there's an option to upload multiple files.These files have to be stored in the database in BLOB format.
What will be the most efficient manner to store these files? There's no constraint on the size or number of file to be uploaded.
Should I upload the files one by one whenever the user clicks the file upload button or
upload them once simultaneously when the whole form gets submitted on save button. Please keep in mind, this is to used by multiple users about ~1000 at a time
Considering that it is a BLOB data, I would consider to use some No-SQL database (MongoDB, RavenDB), where you save just "document" with data, so it's easier to manage in these kind of situations. But you will need more disk space in this case.
What about upload: I would go one after one, as in case if connection drops, at least some of the files are delivered.
On the server side, would look on Redis like in memory cache that always ready to accept user "session" (a sequence of declared quantity of files), and one time all of them delivered, or connection failure the content of that session is saved on the disk.
Just general overview what can be done to give you some hints.
set file upload control multiple attribute to 'multiple' and in the code behind get request user submitted files, then loop through their memory stream and store them in your db as byte arrays
Given the limitations of your scenario (where the images must be stored in (I assume) a single SQL Database) I would look into uploading the images one by one, and I would investigate if the SQL Server Transient Fault Handling with the Exponential back-off strategy could help to try and handle the 'queued' uploads.
Without more details I can't really say.

File upload / did I make a mistake choosing vb.net instead of php?

for the past 3 days I've been trying to create an upload system for multiple files, possibly large, with progress bars.
I've been roaming the web relentlessly for the past few days, and I can say, I am now familiar with most difficulties.
sadly, all the solutions I've found online are not written c# or vbscript, in fact most of them are written in php.
I wouldn't mind switching to another language but the entire website is written in vb.net and for the sake of coherence I thought it might be best to keep with it.
File uploads:
Problem 1 - progress bar:
I understand file uploads will not work with ajax, since the ajax response will only occur after the file had completed its upload.
I understand there is a solution using iFrames but I cannot seem to find any online examples (preferably using vb.net or c#).
I understand there is another alternative using flash. how???
I also understand people are mostly against using iframes but I can't find what the reason might be.
Problem 2 - Multiple Files:
I can have multiple file support with HTML5. great, but IE doesn't support it? well... IE users will just have to upload one file at a time.
Problem 3 - Large files:
how?
I heard something about chunking, and blobs, but these are still just random gibberish words for me. can somebody explain, the meaning and the implementation?
references to reading material are much appreciated even though, if it's on the web, I've probably already read it in my search for my solution.
#DevlshOne has a decent thread with some good information.
Here are the three basic requirements for what I did:
Create Silverlight app for clientside access and upload control. (use app of your choice)
Create an HttpHandler to receive the data in chunks and manage requests.
Create the database backend to handle the files.
Silverlight worked well because I was already in VB (ASP.NET). When used in-browser, as opposed to out-of-browser, the ASP.NET session was shared with Silverlight, so there was no need to have additional security/login measures. Silverlight also allowed me to limit what file types could be selected and allow the user to select multiple files from the same folder.
The Silverlight app grabs the files selected by the user, displays them for editing of certain properties, and then begins the upload when the user clicks the 'upload' button. This sets off a number of threads that each upload chunks of data to the httphandler. The HttpHandler and Silverlight app send and receive in chunks, with the HttpHandler always sending an OK or ERROR message when the request has been processed for the uploaded chunk.
Our specific implementation of file uploading also required some database properties (fields) to be filled out by the user, so we also had inputs for those properties and uploaded them to the server with the file data.
An in-browser Silverlight app can also have parameters passed into it through the html, so I do this with settings like 'max chunk size' or 'max thread count'. I can change the setting in the database and have it apply to all users.
The database backend is basically a few stored procedures (insert your data management preference here) that control the flow of the logic. One table holds completed files (no file data), and a second holds the temp files that are in progress of being uploaded. One stored procedure initiates a new file record in the temp table and processes additional chunk uploads, and another controls the migration of the completely uploaded file from the temp table to the completed table. (A piece of VB code in the HttpHandler migrates the actual binary file data from the temp table to a physical file.)
This seems pretty complex, but the most difficult part would be the interaction with the handler and passing the chunks around (response/requests, uploading successive chunks, etc.). I left out a lot of information, but this is the basic implementation.

Replacing a certain word in a txt file

Following requirements we have users, their passwords and their profile picture stored in a .txt file. A user can be redirected to a profile modification page where they can change their password and/or password picture.
I need to replace the password and/or profile picture name in the .txt file when the user clicks OK.
The users.txt file is laid out like:
mike mike Avatar1
jessica123 123jessica Avatar4
mohd MoHd Avatar3
xiao AxiaoA Avatar2
anna abcANNAabc Avatar1
After doing some research i've tried using:
userFilePath = userFilePath.Replace(Session["password"].ToString(),
passwordTextBox.Text);
The original password is stored on log-in, through the session variable which I was using to find the original text in the file.
But this doesn't work. I'm pretty new to c#. Any help would be appreciated.
Be careful you have to change only the line concerned, many users could have the same passeword, so you have to read the file by line , identify the login concerned and of course not replace anything because also the login or avatar could has the same value as the password, but recreate the line with the new info, and after save the file with the new whole text value.
And just an advice for such needs it's better to use relational database.
Other than storing information in plain text files and saving passwords in clear text which others already mentioned as a bad idea, I think it is best to void direct string modification on the file level. It is best to abstract this away in a (list of) object and the modify the object and save it back to disk. You can easily do this using a library named FileHelpers, if you still want to use plain text files, without reinventing the wheel.
Also thing to consider, if you insist keeping this on a text file, is to switch to a better structured text file like JSON or XML format. You wouldn't need to use the above mentioned library anymore as .NET already comes with de/serializers for both.
If at all possible you should take the advice of the comments on your question and not do this in this manner.
If for some reason that is not possible, then here is a place to get started. You want to load the entire file from the file system into memory during a load phase, generally when your application starts, or first has need of the data.
Once the data is in some structure in memory you can alter like you would alter any object in C#.
Once the changes to the memory are done, you would write the entire thing back out to the file, overwriting the old file.
So your question is a very large one, there is the question of how do you read data from a file? How do you create a data structure in memory to hold this particular set of data? And how do you write the data back out to a file? I'd suggest working on one at a time in that order.
Oh and if you can't have a database, but you can change the file format, switch it to XML or JSON and the process of taking it from a file to memory, and back to a file will be much easier.

Categories

Resources