دریافت آدرس فیزیکی کلاینت

        Dim adapters As NetworkInterface() = NetworkInterface.GetAllNetworkInterfaces()

        Dim adapter As NetworkInterface

        Dim myMac As String = String.Empty


        For Each adapter In adapters

            Response.Write("<BR/>" & adapter.GetPhysicalAddress.ToString())

        Next adapter


منبع: stackOverflow

تعریف URL جدید در برنامه

Uri myUri = new Uri("http://www.example.com?param1=good&param2=bad");

اضافه کردن User Control هنگام اجرای برنامه

Dim myUserControl As Control = Page.LoadControl("userControl.ascx")

Panel1.Controls.Add(myUserControl)


اگر user control دارای خصوصیت custome ی باشد به صورت زیر مقداردهی میشود:


Dim myUC As step1View = CType(Page.LoadControl("/control/step/step1View.ascx"), step1View)
myUC.sort = 5

Panel1.Controls.Add(myUC)

Setting up Web.config to allow uploading of large files by ASP .NET applications

Introduction

During the construction of an intranet application that allows users to upload documents and share information between users, I noticed that when a user tries to upload files that are larger than 4 MB, he is asked for the user/password and even if he enters the correct user/password, the file is not uploaded, and he gets a HTTP 401.1 error.

Of course, this should not be an article, but CodeProject doesn't have a "quick tip section"-like, so here it goes.

The problem

By default, Machine.config is configured to accept HTTP Requests upto 4096 KB (4 MB) and it is reflected in all your ASP.NET applications. You can change the Machine.config file directly, or you can change only the Web.config file of the application(s) you want to.

The solution

Open your Web.config file, and just below the <system.web> tag, add the following tag:

<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096" 
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4" 
appRequestQueueLimit="100" 
enableVersionHeader="true"
/>

Now, just take a look at the maxRequestLength="4096" attribute of the <httpRuntime> tag. As you may have realized, all you need to do is change the value to some other value of your choice (8192 for 8 Mb, 16384 for 16 Mb, 65536 for 64 Mb, and so on...).

That's it. I hope it is useful to you.

ایجاد منوی داینامیک و خواندن آن از پایگاه داده

Function createMenu() As String

        Dim ds As New DataSet()

        Dim cn As New SqlConnection(DB.connectionStirng.ConnectionString())

        Dim cmd As New SqlCommand("SELECT * FROM content order by sort asc", cn)

        Dim da As New SqlDataAdapter(cmd)

        da.Fill(ds)

        Dim table As DataTable = ds.Tables(0)

        Dim parentMenus As DataRow() = table.Select("[parent]=1")

 

        Dim sb = New StringBuilder()

        Dim unorderedList As String = GenerateUL(parentMenus, table, sb)

        Return (unorderedList)

    End Function

 

    Private Function GenerateUL(ByVal menu As DataRow(), ByVal table As DataTable, ByVal sb As StringBuilder) As String

        sb.AppendLine("<ul>")

 

        If menu.Length > 0 Then

            For Each dr As DataRow In menu

                Dim menuText As String = dr("title").ToString()

                Dim line As String = [String].Format("<li><a href=#>{0}</a>", menuText)

                sb.AppendLine(line)

 

                Dim pid As String = dr("id").ToString()

 

                Dim subMenu As DataRow() = table.Select("[parent]=" & pid)

                If subMenu.Length > 0 Then

                    Dim subMenuBuilder = New StringBuilder()

                    sb.AppendLine(GenerateUL(subMenu, table, subMenuBuilder))

                End If

                sb.AppendLine("</li>")

            Next

        End If

 

        sb.Append("</ul>")

        Return sb.ToString()

    End Function

 

ارسال ایمیل با استفاده از Yahoo!, GMail, Hotmail

Server Parameters

Server NameSMTP AddressPortSSL
Yahoo!smtp.mail.yahoo.com587Yes
GMailsmtp.gmail.com587Yes
Hotmailsmtp.live.com587Yes

Sample Code

using System.Net;
using System.Net.Mail;

string smtpAddress = "smtp.mail.yahoo.com";
int portNumber = 587;
bool enableSSL = true;

string emailFrom = "email@yahoo.com";
string password = "abcdefg";
string emailTo = "someone@domain.com";
string subject = "Hello";
string body = "Hello, I'm just writing this to say Hi!";

using (MailMessage mail = new MailMessage())
mail.From = new MailAddress(emailFrom);
{
mail.To.Add(emailTo);
mail.Subject = subject;
mail.Body = body;
mail.IsBodyHtml = true;
// Can set to false, if you are sending pure text.

mail.Attachments.Add(new Attachment("C:\\SomeFile.txt"));
mail.Attachments.Add(new Attachment("C:\\SomeZip.zip"));

using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
{
smtp.Credentials = new NetworkCredential(emailFrom, password);
smtp.EnableSsl = enableSSL;
}
smtp.Send(mail);
}
منبع: