Home
Tool
Json Beautify
Find Web URL
Inventory Management System
Test Mantra RD Service
Calculate your EMI
Project
Inventory Management System
Task Management
Project Management
Mobile Store Management
Money Transfer Tool
Store Management
About Us
Contact
Login
Registration
Search
ASP.net,C-Sharp
Upload file in folder using asp.net c#
By
Csharp Code
Apr 26 2020
1327 View's
0 Comment's
Like (
0
)
Dislike (
0
)
You can upload files or images, follow this code.
Add this HTML in yours .aspx page
-
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<div class="form-element-list mg-t-30">
<div class="cmp-tb-hd">
<h2>Upload File</h2>
</div>
<div class="row">
<div class="col-lg-12 col-md-4 col-sm-4 col-xs-12">
<div class="form-group">
<label>Example Attachment</label>
<asp:FileUpload runat="server" ID="FuFile"></asp:FileUpload>
</div>
</div>
</div>
<div class="form-example-int mg-t-15 text-center">
<asp:LinkButton runat="server" ID="LnkBlogSubmit" class="btn btn-success notika-btn-success waves-effect" ValidationGroup="Blog" Onclick="
LnkConfirmationYes_Click
" Text="Submit"></asp:LinkButton>
<asp:LinkButton runat="server" ID="LnkBlogBack" class="btn btn-warning notika-btn-success waves-effect" PostBackUrl="dashboard" Text="Back"></asp:LinkButton>
</div>
</div>
</div>
</div>
After added HTML , add .aspx.cs
This function is return status of upload file in TRUE or FALSE and also return
FileUpload fileUpload - Pass the file upload control.
string folder - Pass the folder name, which you want to store the file
ref string uploadedFileName - get the file name
protected void LnkConfirmationYes_Click(object sender, EventArgs e)
{
string uploadedFileName = string.Empty;
bool isExampleUploaded = UploadDocument(FuFile, "../folderName", ref uploadedFileName);
}
public bool UploadDocument(FileUpload fileUpload, string folder, ref string uploadedFileName)
{
string baseUrl = HttpContext.Current.Request.Url.Host;
bool isUploaded = false;
string saveLocation = string.Empty;
string fileName = string.Empty;
if ((fileUpload.PostedFile != null) && (fileUpload.PostedFile.ContentLength > 0))
{
fileName = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);
fileName = (DateTime.UtcNow.Ticks + "_" + fileName);
saveLocation = HttpContext.Current.Server.MapPath(folder) + fileName;
try
{
fileUpload.PostedFile.SaveAs(saveLocation);
isUploaded = true;
}
catch (Exception)
{
isUploaded = false;
}
}
else
{
isUploaded = false;
}
uploadedFileName= fileName;
return isUploaded;
}
This function you can use anywhere as your requirement.
0 Comment's
Comment Form
Required
Submit Comment
Csharp Code
If opportunity doesn’t knock, build a door.⛩
Popular Post
WPF
How to Use Logger in WPF Application
By
Csharp Code
Jun 07 2022
C-Sharp
Update Specific Users Out of Oce Settings C# with Example
By
Csharp Code
Jun 06 2022
C-Sharp
Retrieve Specified User''s Out of O ce Settings C# with Example
By
Csharp Code
Jun 06 2022
C-Sharp
Large Object Heap compaction C# with Example
By
Csharp Code
Jun 06 2022
C-Sharp
Weak References C# with Example
By
Csharp Code
Jun 06 2022
C-Sharp
Source code in the view C# with Example
By
Csharp Code
Jun 06 2022
Notifications