Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Asp.net Get File Extension (Path) from Fileupload Control using C#, VB.NET

Oct 12, 2015
Introduction

Here I will explain how to get file extension from fileupload in
asp.net using c#, vb.net with example or asp.net get uploaded file extension or path from fileupload control using c#, vb.net with example. By using “Path.GetExtension” properties we can get uploaded file extension or path from fileupload control in asp.net using c#, vb.net.


To get file extension from fileupload control we need to write the code like as shown below


string strpath = System.IO.Path.GetExtension(fileupload1.FileName);

If you want to check it in complete example open your aspx page and write the following code


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Create, Write and Read Cookies in Asp.net using C#, VB.NET</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="btnCreate" runat="server" Text="Create Cookies" onclick="btnCreate_Click" />
<asp:Button ID="btnGet" runat="server" Text ="Get Cookie Values" onclick="btnGet_Click" /><br /><br />
<asp:Label ID="lblResult" runat="server"/>
</div>
</form>
</body>
</html>

After completion of aspx page add following namespaces in codebehind

C# Code


using System;

After completion of adding namespaces you need to write the code like as shown below


protected void btnGet_Click(object sender, EventArgs e)
{
string strpath = System.IO.Path.GetExtension(fileupload1.FileName);
lblExtension.Text = "Uploaded File Extension: " + strpath;
}

VB.NET Code


Imports System.Web
Partial Class VBCode
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
Protected Sub btnGet_Click(sender As Object, e As EventArgs)
Dim strpath As String = System.IO.Path.GetExtension(fileupload1.FileName)
lblExtension.Text = Convert.ToString("Uploaded File Extension: ") & strpath
End Sub
End Class

Demo

Please check below demo to get uploaded file path or extension from fileupload control in asp.net using c#, vb.net.

Output of Asp.net Get File Extension (Path) from Fileupload Control using C#, VB.NET


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

1 comments :

Hothorasman Panjaitan said...

Mr suresh
how to creat comments after login

Give your Valuable Comments

Other Related Posts

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.