Tag Archives: asp.net

Access HTML control’s value from code-behind

if you wish to access the HTML Control’s value from code behind, that’s possible.

let’s assume you have

<input type=\"text\" name=\"allowFillInChoices\" runat=\"server\"/>

and you wish to access the value of allowFillInChoices, you can just use code below to achieve that.

Page.Request.Form["allowFillInChoices"]

Incoming search terms:

C# – EpochTime

Snipplet code to convert current date time to epoch time
you may go to http://www.epochconverter.com/ to check the result.

public long GetEpochTime()
{
DateTime dtCurTime = DateTime.Now;
DateTime dtEpochStartTime = Convert.ToDateTime("1/1/1970 00:00:00 AM");
TimeSpan ts = dtCurTime.Subtract(dtEpochStartTime);

long epochtime;
epochtime = ((((((ts.Days * 24) + ts.Hours) * 60) + ts.Minutes) * 60) + ts.Seconds);
return epochtime;
}

Incoming search terms:

Check File Exist from Remote Server

Some snippet code for checking file exists from remote server using WebClient.

        private bool RemoteFileExists(string url)
        {
            bool bResult = false;
            using (WebClient client = new WebClient())
            {
                try
                {
                    client.UseDefaultCredentials = true;
                    Stream stream = client.OpenRead(url);
                    if (stream != null)
                        bResult = true;
                    else
                        bResult = false;
                }
                catch
                {
                    bResult = false;
                }
            }
            return bResult;
        }

Incoming search terms:

DNN Site Map

If your DNN website need a site map, you can find the open source application from [here].

After deploy the DNN SiteMap, the DNN really solve my problem, but I found out the SiteMap’s parent node order is not same with Tab Menu’s Order.

Here the Solution,

  1. download the source code [here]
  2. launch the VS.NET 2005 and open the solution
  3. double click SqlDataProvider.cs
  4. check out 2 methods here – GetRootNodesFromDb() and GetChildNodesFromDb(int parentTabId)
  5. notice the last line of each method which ORDER BY t.TabId
  6. ok, is show time now, replace  ORDER BY t.TabId to ORDER BY t.TabOrder, t.TabName –t.TabId
  7. you can compare both tab menu and sitemap parent node is tally now.

Incoming search terms:

ASP.NET Large File Download Error

If you have an ASP.NET application which allow users to download files from the system and these files size not in small size. Each file more than 50mb, for instance.

When an user click on the file to download, your application will prompt an error in the middle of downloading a file. Wondering what happen? Perhaps you need to check your code.

Response.Flush(); <- this is very important line. Must include this.

Below is a complete code of downloading a file.

Response.AddHeader("content-disposition", "attachment; filename=" + System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.ContentType = "Application/octet-stream";
Response.Flush();
Response.BinaryWrite((byte[])objCustomInfo.File_Attachment);
Response.End();

Incoming search terms:

C# source code for DotNetNuke 5.4.2

Finally, we can [download] the c# source code for DotNetNuke Portal.

This is not a fully tested application. So use it as your own risk.

You can go to [DNN Forum] to discuss this topic.

Incoming search terms:

DotNetNuke Module Development

For those who wish to learn or know more about DNN module development but do not know where to start.

Here the link for you to start.

  1. Creating a DNN Module and Understanding DNN Architectural Approach [Click Here]
  2. Creating a DotNetNuke® Module – For Absolute Beginners [Click Here]
  3. Creating a Super-Fast and Super-Easy DotNetNuke® Module – for Absolute Beginners [Click Here]

Before launch your visual studio.NET 2005, please make sure you installed the DNN template & starter kit which you can find it [here], also DNN Source Code Version which you can download from [www.dotnetnuke.com]

mailto in GridView

An application required to have Microsoft Outlook launch after click the user’s email.

Here the snippet code from gridview,

<asp:TemplateField HeaderText="Email" SortExpression="Email">
<ItemTemplate>
<asp:HyperLink ID="hylinkEmail" runat="server" NavigateUrl='<%#(Eval("Email", "mailto:{0}"))%>'>
<%#DataBinder.Eval(Container.DataItem, "Email")%>
</asp:HyperLink>
</ItemTemplate>
<ItemStyle />
</asp:TemplateField>

Incoming search terms:

SqlHelper.ExecuteScalar in DotNetNuke Modules

To deal with a complex business logic, you may write complex T-SQL in stored procedure. It may return -9, -5, -1, 0, 1, 2…. and so on.

We have to use SqlHelper.ExecuteScalar instead of SqlHelper.ExecuteNonQuery.

Example,

public override long DeleteUser(long callingUserId, long userId)
{
SqlParameter[] paramArray = new SqlParameter[3];
paramArray[0] = new SqlParameter("@piCallingUserId", callingUserId);
paramArray[1] = new SqlParameter("@piDeletedUserId", userId);

paramArray[2] = new SqlParameter("@oiRetVal", 99);

paramArray[2].Direction = ParameterDirection.Output;

SqlHelper.ExecuteScalar(ConnectionString, CommandType.StoredProcedure, GetFullyQualifiedName("User_Del_User"), paramArray);

return long.Parse(paramArray[2].Value.ToString());
}

Incoming search terms:

extending Enum

Today I m faced a problem when I want to re-use Enum without major change on the based code.

Here the simple example,

I got a drop down list which bind Enum, here the sample code:

public enum Gender
{
[Description("I m a Male")] M,
[Description("I m a Female")] F
}

if you just bind the Enum, your dropdownlist will simply show you “M” and “F”, what if I want to show “I m a Male” and “I m a Female”?

OK, here the trick. (I will put the Author URL once I found, I m forgot the link)

in PageLoad or Code Behind,

using System.ComponentModel;
using System.Reflection;

public static string GetDescription(Enum value)
{
FieldInfo fi = value.GetType().GetField(value.ToString());
DescriptionAttribute[] attributes =
(DescriptionAttribute[])fi.GetCustomAttributes(
typeof(DescriptionAttribute), false);
return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
}

Here you will see gender.ToString(“d”), it will return 0 or 1, if you simply put ToString(), it will return M or F

foreach (Gender gender in Enum.GetValues(typeof(Gender)))
{
this.ddlGender.Items.Add(new ListItem(GetDescription(gender ), gender.ToString("d")));
}

Hope this Help

Related Posts with Thumbnails
Get Adobe Flash player
%d bloggers like this: