tags:

views:

125

answers:

2

What is C# equivalent of include function in php??i have to convert the following code in php to C#

if (file == "") file = str_replace(" ", "", family).strtolower(style) + " +ok sir php";
if (defined("FPDF_FONTPATH"))
file = FPDF_FONTPATH + file;
include(file);
+5  A: 

There is no equivalent in C# - you cannot dynamically include a file into your source code.

The way to reuse code in C# is to use controls. As you are asking about PHP, I assume you mean ASP.NET and not Winforms or WPF, so you will need to create user controls or custom controls which you can reuse in your website.

Oded
A: 

Some code I used to "include" a menu file from another server.

    if (Application["menu"] != null)
    {
        litMenu.Text = Application["menu"].ToString();
    }
    else
    {
        try
        {
            System.Net.WebRequest wrq = System.Net.WebRequest.Create(ConfigurationManager.AppSettings["MenuPath"]);
            System.Net.WebResponse wrp = wrq.GetResponse();

            System.IO.StreamReader sr = new System.IO.StreamReader(wrp.GetResponseStream());
            litMenu.Text = sr.ReadToEnd();
            Application["menu"] = litMenu.Text;
        }
        catch
        {
            Application["menu"] = litMenu.Text;
        }

    }

The goal was to make our Intranet(PHP) and management backend(ASP.NET) look like the same system.

barc0de