Solved

cookies in windows form?

Posted on 2007-11-21
11
659 Views
Last Modified: 2010-04-21
I'm an ASP.Net developer and web has "cookies" to save user's selection.

What's equal to Cookies in WinForm? In my login page, I have 2 radiobutons. I dont want the user to keep selecting them everytime they login. How can I save this user selection in a cookie?

I'm a VB.Net-er but for this, I'm using C# to learn C#.
0
Comment
Question by:Camillia
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20328464
You can save user preferences in Windows registry. To save, you can do something like:

                RegistryKey regKey = Application.CommonAppDataRegistry;
                regKey.SetValue("LoginName", loginname);

To retrieve:

                RegistryKey regKey = Application.CommonAppDataRegistry;
                loginname = regKey.GetValue("LoginName").ToString();
0
 
LVL 20

Accepted Solution

by:
REA_ANDREW earned 200 total points
ID: 20328470
Add a settings file and declare the scope as User not Application

Andrew
0
 
LVL 7

Author Comment

by:Camillia
ID: 20328479
Thanks.I thought about the registery since our vendor app does that. But i thought there's a way around not playing around with a registery. Maybe save in a config file or something . But I'll try that.
0
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 7

Author Comment

by:Camillia
ID: 20328538
Then how to save/retreive in the settings File. I added it. Do see the "User" dropdown? User's name needs to be saved in that??
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 20328556
OK so say you simply add a new settings file and it is callded Settings1.settings.  It is simply this:

Settings1.Default.Username = "Andy";

where Username is the name of the setting which I have declared as type string and scope User

Andrew

:-)
0
 
LVL 55

Assisted Solution

by:Jaime Olivares
Jaime Olivares earned 100 total points
ID: 20328576
0
 
LVL 8

Assisted Solution

by:Autoeforms
Autoeforms earned 100 total points
ID: 20328581
If you do not want to save info to the registry you can save it to a config file using serialization.  This is the strategy I use.  Plus I store the info in the directory on the server so it is available regardless of the machine they log into.

http://www.java2s.com/Code/VB/File-Directory/Serialize-to-XML.htm

good luck
Greg
0
 
LVL 7

Author Comment

by:Camillia
ID: 20328591
let me read. I did this : Settings1 userSetting = new Settings1();

but seems like that's an overkill. Thanks Jaime, let me read the links.
0
 
LVL 70

Assisted Solution

by:Éric Moreau
Éric Moreau earned 100 total points
ID: 20328783
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 20329524
?

No it is static, do not instantiate anything:

Simply

Settings1.Default.Username

0
 
LVL 7

Author Closing Comment

by:Camillia
ID: 31410382
thanks. have another question but will close this. It works great.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is about my first experience with programming Arduino.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question