Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone . .

I need some help in my project . . Its regarding online store . . Suppose there are 5 clients of mine . . They should be able to login to my website and change the contents or menu's, price of their store from my website . . so whenever they need to add/delete something they will login to my website and can change things. . Each store is different . . How should i start with this ? i am confused :(
Posted

You can create the application setting for each user using IsolatedStorage. Here is the sample code to store and retrieve the application settings:

VB
Public Class AppSettings
   Private _configFileName As String 'local var to hold the config file name
   Private _configFileType As Config 'local var to hold the config file type (private or shared)

   'config file options
   Public Enum Config
      SharedFile  'all users use the same config file
      PrivateFile 'each user has their own config file
   End Enum
 
   'constructor
   Public Sub New(ByVal ConfigFileType As Config)
      _configFileType = ConfigFileType 'remember this setting

      InitializeConfigFile() 'setup the filename and location
   End Sub
 
   'initialize the apps config file, create it if it doesn't exist
   Private Sub InitializeConfigFile()
      Dim sb As New Text.StringBuilder
 
      'build the path\filename depending on the location of the config file
      Select Case _configFileType
         Case Config.PrivateFile 'each user has their own personal settings
            'use "\documents and settings\username\application data" for the config file directory
            sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
         Case Config.SharedFile 'all users share the same settings
            'use "\documents and settings\All Users\application data" for the config file directory
            sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData))
      End Select
 
      'add the product name
      sb.Append("\")
      sb.Append(Application.ProductName)
 
      'create the directory if it isn't there
      If Not IO.Directory.Exists(sb.ToString) Then
         IO.Directory.CreateDirectory(sb.ToString)
      End If
 
      'finish building the file name
      sb.Append("\")
      sb.Append(Application.ProductName)
      sb.Append(".config")
 
      _configFileName = sb.ToString 'completed config filename

      'if the file doesn't exist, create a blank xml
      If Not IO.File.Exists(_configFileName) Then
         Dim fn As New IO.StreamWriter(IO.File.Open(_configFileName, IO.FileMode.Create))
         fn.WriteLine("")
         fn.WriteLine("<configuration>")
         fn.WriteLine("  <appsettings>")
         fn.WriteLine("    <!--   User application and configured property settings go here.-->")
         fn.WriteLine("    <!--   Example: <add key=""settingName"" value=""settingValue""/> -->")
         fn.WriteLine("  </appsettings>")
         fn.WriteLine("</configuration>")
         fn.Close() 'all done
      End If
   End Sub
 
   'get an application setting by key value
   Public Function GetSetting(ByVal key As String) As String
      'xml document object
      Dim xd As New Xml.XmlDocument
 
      'load the xml file
      xd.Load(_configFileName)
 
      'query for a value
      Dim Node As Xml.XmlNode = xd.DocumentElement.SelectSingleNode( _
                                "/configuration/appSettings/add[@key=""" & key & """]")
 
      'return the value or nothing if it doesn't exist
      If Not Node Is Nothing Then
         Return Node.Attributes.GetNamedItem("value").Value
      Else
         Return Nothing
      End If
   End Function
 
   'save an application setting, takes a key and a value
   Public Sub SaveSetting(ByVal key As String, ByVal value As String)
      'xml document object
      Dim xd As New Xml.XmlDocument
 
      'load the xml file
      xd.Load(_configFileName)
 
      'get the value
      Dim Node As Xml.XmlElement = CType(xd.DocumentElement.SelectSingleNode( _
                                         "/configuration/appSettings/add[@key=""" & _
                                         key & """]"), Xml.XmlElement)
      If Not Node Is Nothing Then
         'key found, set the value
         Node.Attributes.GetNamedItem("value").Value = value
      Else
         'key not found, create it
         Node = xd.CreateElement("add")
         Node.SetAttribute("key", key)
         Node.SetAttribute("value", value)
 
         'look for the appsettings node
         Dim Root As Xml.XmlNode = xd.DocumentElement.SelectSingleNode("/configuration/appSettings")
 
         'add the new child node (this key)
         If Not Root Is Nothing Then
            Root.AppendChild(Node)
         Else
            Try
               'appsettings node didn't exist, add it before adding the new child
               Root = xd.DocumentElement.SelectSingleNode("/configuration")
               Root.AppendChild(xd.CreateElement("appSettings"))
               Root = xd.DocumentElement.SelectSingleNode("/configuration/appSettings")
               Root.AppendChild(Node)
            Catch ex As Exception
               'failed adding node, throw an error
               Throw New Exception("Could not set value", ex)
            End Try
         End If
      End If
 
      'finally, save the new version of the config file
      xd.Save(_configFileName)
   End Sub
End Class
 
Share this answer
 
Thanks Ganesan Senthilvel . .
Can i get your Email Address ?
 
Share this answer
 
I am not getting from where to start on this project . . i am new to this . . If you can give me some resources then that ll be nice of you . . I am doint it from scratch . . :( Please help me !
 
Share this answer
 
Comments
André Kraak 10-Mar-12 4:06am    
If you have a question about or comment on a given solution use the "Have a Question or Comment?" option beneath the solution. When using this option the person who gave the solution gets an e-mail message and knows you placed a comment and can respond if he/she wants.

Please move the content of this solution to the solution you are commenting on and remove the solution.
Thank you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900