Recent News

Showing posts with label DOT Net. Show all posts
Showing posts with label DOT Net. Show all posts

MULTI FILE UPLOAD USING JQUERY

Herewith I have explained and given the code for multiple file upload using jquery.
We know all the normal upload functionality. But someone of us wants the multiple file upload in .NET. Here jquery makes that very easy.
We just use the same asp:fileupload control. If you want to accept only jpg,png only you no need to go for a customvalidator tocheck the file extension. You just add the accept="jpg|png". Thats it. It allows only files which has the extension of above.
Ok let us see the code below,

HEAD SECTION:
<script src="Scripts/jquery-1.3.2.js" type="text/javascript"></script>
<script src="Scripts/jquery.MultiFile.js" type="text/javascript"></script>
 
BODY TAG:
<div>

<asp:FileUpload ID="fupImage" runat="server" class="multi" accept="" />
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload All" OnClick="btnUpload_Click" />
</div>

Thats it about in the UI page(aspx).
Let us see the code behind page,

the following code should be inside in the upload button event,

try

{
// Get the HttpFileCollection
HttpFileCollection hfc = Request.Files;
Guid newid = new Guid();
newid = System.Guid.NewGuid();
for (int i = 0; i < hfc.Count; i++)
{
HttpPostedFile hpf = hfc[i];
if (hpf.ContentLength > 0)
{
hpf.SaveAs(Server.MapPath("Files") + "\\" +
System.IO.Path.GetFileName(newid + hpf.FileName));
Response.Write("Uploaded Successfully <br/>");
}
}
}
catch (Exception ex)
{
// ERROR OCCURED
}
 
Feel free to post your comments here!... If any one wants the whole solution post your mailid here. I will send mail to you personally.....
 
“You have to dream before your dreams can come true.” - A P J


watermark textbox using Ajax control

This is pretty simple compared to jquery. Since we need refer a dll only. we dont want any script for this. we just include that reference into our website.

Please have a look at the coding.......

<asp:TextBox runat="server" ID="txtSearch"></asp:TextBox>
<ajaxToolkit:TextBoxWatermarkExtender ID="twSearch" runat="server" TargetControlID="txtSearch"
WatermarkText="Search Products..." />
<span class="search_button">
<asp:ImageButton ID="butSearch1" runat="server" ImageAlign="Right" OnClick="butSearch1_Click"
Height="30px" />
</span>

Watermark Textbox using jquery

Here is the coding for Watermark inside a textbox. That is initially the message will show inside the textbox. Once you click on the textbox it will disappear. This is used by jquery.

CSS:

<style type="text/css" media="screen">
.water
{
font-family: Tahoma, Arial, sans-serif;
color: blue;
}
</style>

 
SCRIPT:
 
        <script src="js/jquery-1.2.6.min.js" type="text/javascript"></script>
 
DESIGN:
  <div>


<h2>

Watermarked TextBox </h2>

<br />
<asp:TextBox ID="txtFirstName" class="water" Text="Enter First Name" ToolTip="Enter First Name" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtLastName" class="water" Text="Enter Last Name" ToolTip="Enter Last Name" runat="server"></asp:TextBox> <br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" ValidationGroup="vgNews" /></div>



 
Please give your comments if you need any clarification.... Also I will post watermark using ajax in the next post... Happy Coding!!!

If you need this Jquery please click here to download

Create XML file

Hi All,
   Here I have given the sample code to create a simple XML from .NET.
Please post your comments after review this....

string strfile = Server.MapPath("~/App_Data/simplexmlcreation.xml");
XmlTextWriter writexml = new XmlTextWriter(strfile, System.Text.Encoding.UTF8);
try
{
// write the top element and encode type
writexml.WriteStartDocument();
// write the starting element or root element
writexml.WriteStartElement("IPL");
// write first set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Chennai Super Kings");
writexml.WriteAttributeString("Points", "40");
writexml.WriteAttributeString("Captain", "Raina");
writexml.WriteString("CSK HAS MATHEW HAYDEN");
writexml.WriteEndElement();

//// write Second set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Kolkatta Knight Riders");
writexml.WriteAttributeString("Points", "45");
writexml.WriteAttributeString("Captain", "Saurav");
writexml.WriteString("KKR HAS Saurav Ganguly");
writexml.WriteEndElement();

//// write Third set of records
writexml.WriteStartElement("team");
// write the attributes
writexml.WriteAttributeString("Name", "Royal Challangers Bangalore");
writexml.WriteAttributeString("Points", "55");
writexml.WriteAttributeString("Captain", "Kumble");
writexml.WriteString("KKR HAS Kalis");
writexml.WriteEndElement();

// Close the root Element
writexml.WriteEndElement();
//close the XML DOC
writexml.WriteEndDocument();
}

catch
{
throw;
}

finally
{
writexml.Close();
}



Thanks for reading my POST..... Keep Coding!!!!!!!

AUTHENTICATION and AUTHORIZATION

The web.config file has all of the configuration settings on an Application.
Authentication is the process of determining the authenticity of a user based on the user’s credentials.
Whenever a user logs in to an application, the user is first authenticated and then authorized.

1. Forms Authentication
2. Windows Authentication
3. Passport Authentication


You can set it in the web.config file as below,

or or

1. Forms Authentication:

This type of authentication is based on cookies. The username and password is stored in Database.This Forms authentication supports both Session and Cookies.
If the cookie isn't present, ASP.NET redirects the user to a web form you provide.
SYNTAX:


2. Windows Authentication:

This type of authentication is default one. Here a user can authenticated by their own windows account. So that this kind of Authentication is used only for Intranet not for web.
SYNTAX:


3. Passport Authnetication:
This passport authentication is the authentication service that uses the Microsoft's Passport Services. It allows the user to create a single sign in name and password to authenticated.

SYNTAX:


AUTHORIZATION:

It is the process of finding the accessibilty for a previously authenticated user.Authorization is only works with the Authenticated User/Person.

Download a Folder or File from .NET

Hi All,

  The below code is used to download the files from our .net coding...

#region downloadfile



public static bool downloadfile(string filename, string path)


{


try


{


FileStream sourceFile;


HttpResponse response = HttpContext.Current.Response;


response.ContentType = "application/x-rar-compressed";


response.AddHeader("content-disposition", "attachment; filename=" + filename + Path.GetExtension(path).ToString());


sourceFile = new FileStream(path, FileMode.Open);


long FileSize;


FileSize = sourceFile.Length;


byte[] getContent = new byte[(int)FileSize];


sourceFile.Read(getContent, 0, (int)sourceFile.Length);


sourceFile.Close();


sourceFile.Dispose();


response.BinaryWrite(getContent);


response.Flush();


response.Clear();


response.Close();


return true;


}


catch (Exception ex)


{


return false;


}


}


#endregion
 
 
 Happy Coding!!!!!!!

What is DataSet ?

A DataSet is an in memory representation of data loaded from any data source. Even though the most common data sourceis database, we can use DataSet to load data from other data sources including XML files etc. In this article, we will talk about the role of DataSet in manipulating data from database.

In .NET, a DataSet is a class provided by the .NET Framework. The DataSet class exposes several proeprties and methods that can be used to retrieve, manipulate and save data from various data sources.

Followers

Top Commentators

Recent Comments | Recent Posts


bottom