Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Translate to C# from vb

Posted on 2009-07-12
3
Medium Priority
?
280 Views
Last Modified: 2012-06-21
How can i translate the following Class from ASP Classic vb to a C#.net Class

I am just learning C# translating between languages is beyond my capabilities at the moment i have no knowledge of VB

Thank you
Class ASPObjects
 
    'returns Request object variables
    'QType here represents a collection
    '   (QueryString, Form or <A class=iAs style="FONT-WEIGHT: normal; FONT-SIZE: 100%; PADDING-BOTTOM: 1px; COLOR: darkgreen; BORDER-BOTTOM: darkgreen 0.07em solid; BACKGROUND-COLOR: transparent; TEXT-DECORATION: underline" href="#" target=_blank itxtdid="3809288">Server</A>(ServerVariables))
    Public Function GetRequestVariable(ByVal Key, ByVal QType)
        Select Case lcase(QType)
            Case "session"
                GetRequestVariable = CStr(session(Key))
            Case "querystring"
                GetRequestVariable = CStr(Request.QueryString(Key).Item)
            Case "form"
                GetRequestVariable = CStr(Request.Form(Key).Item)
            Case "server"
                GetRequestVariable = CStr(Request.ServerVariables(Key).Item)
            Case Else
                GetRequestVariable = CStr(Request(Key).Item)
        End Select
    End Function
 
    'returns Session object variables
    Public Function GetSessionVariable(ByVal Key)
        GetSessionVariable = Session(Key)
    End Function
 
    'sets Session object variable
    Public Function SetSessionVariable(ByVal Key, ByVal Value)
        Session(Key) = Value
        SetSessionVariable = ""
    End Function
 
    Public Function encodeURL(ByVal p_string)
        encodeURL = server.urlencode(p_string)
    End Function
 
End Class

Open in new window

0
Comment
Question by:QuinnDester
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
3 Comments
 
LVL 15

Accepted Solution

by:
jinal earned 2000 total points
ID: 24833882

public class ASPObjects
{
    static ASPObjects()
    {
        //
        // TODO: Add constructor logic here
        //
    }
 
    public static string GetRequestVariable(string key, string Qtype)
    {
        string returnVariable = string.Empty;
        switch (Qtype.ToLower())
        {
            case "session":
                returnVariable = HttpContext.Current.Session[key].ToString();
                break;
            case "querystring":
                returnVariable = HttpContext.Current.Request.QueryString[key];
                break;
            case "form":
                returnVariable = HttpContext.Current.Request.Form[key];
                break;
            case "server":
                returnVariable = HttpContext.Current.Request.ServerVariables[key];
                break;
            default:
                returnVariable = HttpContext.Current.Request[key];
                break;
        }
        return returnVariable;
    }
 
    public static string EncodeUrl(string p_string)
    {
        return HttpUtility.UrlEncode(p_string);
    }
 
    public static string GetSessionVariable(string key)
    {
        if (HttpContext.Current.Session[key] != null)
        {
            return HttpContext.Current.Session[key].ToString();
        }
        else
        {
            return "";
        }
    }
 
    public static void SetSessionVariable(string key, object value)
    {
        HttpContext.Current.Session[key] = value;
    }
}

Open in new window

0
 
LVL 15

Assisted Solution

by:jinal
jinal earned 2000 total points
ID: 24833887
Hello ,

You can use above class as simple

string  encodeURL = ASPObjects.EncodeUrl("http://www.expert-exchange.com");

I created static class for that. You want to go like

ASPObjects obj = new ASPObjects();
obj.EncdoeUrl("");
then use attached class with this comment.

using System;
using System.Collections.Generic;
using System.Web;
 
/// <summary>
/// Summary description for Class1
/// </summary>
public class ASPObjects
{
    public ASPObjects()
    {
        //
        // TODO: Add constructor logic here
        //
    }
 
    public string GetRequestVariable(string key, string Qtype)
    {
        string returnVariable = string.Empty;
        switch (Qtype.ToLower())
        {
            case "session":
                returnVariable = HttpContext.Current.Session[key].ToString();
                break;
            case "querystring":
                returnVariable = HttpContext.Current.Request.QueryString[key];
                break;
            case "form":
                returnVariable = HttpContext.Current.Request.Form[key];
                break;
            case "server":
                returnVariable = HttpContext.Current.Request.ServerVariables[key];
                break;
            default:
                returnVariable = HttpContext.Current.Request[key];
                break;
        }
        return returnVariable;
    }
 
    public string EncodeUrl(string p_string)
    {
        return HttpUtility.UrlEncode(p_string);
    }
 
    public string GetSessionVariable(string key)
    {
        if (HttpContext.Current.Session[key] != null)
        {
            return HttpContext.Current.Session[key].ToString();
        }
        else
        {
            return "";
        }
    }
 
    public void SetSessionVariable(string key, object value)
    {
        HttpContext.Current.Session[key] = value;
    }
}

Open in new window

0
 
LVL 15

Assisted Solution

by:jinal
jinal earned 2000 total points
ID: 24833892
Hello,

This is code file.

ASPOjects.cs.txt
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

688 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