Hello
Am doing a VB code conversion into C# and facing some below listed errors
Below is my VB CODE
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
Page.Response.Expires = -2400
If Page.Session("auth_EmployeeID") <> Convert.ToInt32(Page.User.Identity.Name) Then Call Reset_Session_Data(Page)
If _restrictto_groupid <> 0 Then
If InStr(Session("user_groups"), "~" & _restrictto_groupid & "~") = 0 Then
Server.Transfer("/access_denied.aspx")
End If
End If
Dim filename As String
Dim fileandquery As String
fileandquery = Page.Request.Path & "?index=5"
Dim query_pos As Integer
query_pos = InStr(fileandquery, "?")
If query_pos <> 0 Then
filename = Left(fileandquery, query_pos - 1)
Else
filename = fileandquery
End If
If _parent_Nav_Area <> "" Then filename = _parent_Nav_Area
Dim conn As New SqlConnection(ConfigurationSettings.AppSettings("ConnectionString"))
Dim command As New SqlCommand("sproc_CP_Navigation_PathGet", conn)
command.CommandType = CommandType.StoredProcedure
Dim param As SqlParameter = command.Parameters.Add("@filename", SqlDbType.VarChar, 100)
param.Value = filename
conn.Open()
Dim pathReader As SqlDataReader = command.ExecuteReader()
nav_path.Text = ""
Dim access_granted As Boolean = False
If pathReader.HasRows Then
Do While pathReader.Read()
If pathReader.Item("depth") <> 1 Then
nav_path.Text &= " :: "
Else
nav_path.Text &= "> "
End If
access_granted = False
If pathReader.Item("security_group_required") Is DBNull.Value Then
access_granted = True
Else
access_granted = Check_GroupMembership(pathReader.Item("security_group_required"))
End If
If Not (pathReader.Item("link") Is DBNull.Value) And access_granted Then
If InStr(pathReader.Item("link"), filename) = 0 Or _parent_Nav_Area <> "" Then
nav_path.Text &= "<a href=""" & Page.Request.ApplicationPath & "flashnav/" & pathReader.Item("link") & """>" & pathReader.Item("label") & "</a>"
Else
nav_path.Text &= pathReader.Item("label")
End If
Else
nav_path.Text &= pathReader.Item("label")
End If
Loop
End If
pathReader.Close()
conn.Close()
pathReader = Nothing
command = Nothing
conn = Nothing
End Sub
Here is my C# CODE
protected void Page_Load(object sender, EventArgs e)
{
Page.Response.Expires = -2400;
if (Page.Session["auth_EmployeeID"] != (Page.User.Identity.Name).ToString())
{
Reset_Session_Data(Page);
}
if (_restrictto_groupid != 0)
{
if (String.InStr(Session["user_groups"], "~" + _restrictto_groupid + "~") == 0)
{
Server.Transfer("access_denied.aspx");
}
}
string filename = null;
string fileandquery = null;
fileandquery = Page.Request.Path + "?index=5";
int query_pos = 0;
query_pos = String.InStr(fileandquery, "?");
if (query_pos != 0)
{
filename = String.Left(fileandquery, query_pos - 1);
}
else
{
filename = fileandquery;
}
if (!string.IsNullOrEmpty(_parent_Nav_Area))
filename = _parent_Nav_Area;
SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand command = new SqlCommand("sproc_CP_Navigation_PathGet", conn);
command.CommandType = CommandType.StoredProcedure;
SqlParameter param = command.Parameters.Add("@filename", SqlDbType.VarChar, 100);
param.Value = filename;
conn.Open();
SqlDataReader pathReader = command.ExecuteReader();
nav_path.Text = "";
bool access_granted = false;
if (pathReader.HasRows)
{
while (pathReader.Read())
{
if (Convert.ToInt32(pathReader["depth"]) != 1)
{
nav_path.Text += " :: ";
}
else
{
nav_path.Text += "> ";
}
access_granted = false;
if (object.ReferenceEquals(pathReader["security_group_required"], DBNull.Value))
{
access_granted = true;
}
else
{
access_granted = Check_GroupMembership(pathReader["security_group_required"]);
}
if ((!object.ReferenceEquals(pathReader["link"], DBNull.Value)) & access_granted)
{
if (String.InStr(pathReader["link"], filename) == 0 | !string.IsNullOrEmpty(_parent_Nav_Area))
{
nav_path.Text += "<a href="\""" page.request.applicationpath="">" + pathReader["label"] + "</a>";
}
else
{
nav_path.Text += pathReader["label"];
}
}
else
{
nav_path.Text += pathReader["label"];
}
}
}
pathReader.Close();
conn.Close();
pathReader = null;
command = null;
conn = null;
}
after conversion VB to C# of the code below is the error:
if (String.InStr(pathReader["link"], filename) == 0 | string.IsNullOrEmpty(_parent_Nav_Area))
The name ' Strings' does not exists in current context.
If I replace this Strings keyword to String then the InStr which is its associated fuctions gets error: String does not contain a definition of 'InStr', I known to this fact that 'InStr' is not accessible in C# can anyone please suggest an alternative for the same..