|
Hi All,
Some long time I have not been using File Upload, but when I tried now I need to write lot of Client side scripting to validate the size and type of the files. Can somebody please help me in implementing the above functionalities like immediately after use selecting a file it checks the file size and its type if they are not matching it throws error instead of clicking some other button or etc.
If I can do this by using Server side code that's better but if I have to use the Client side code then fine too. Please help me in this regards.
Any help may be code snippet, a link or even a suggestion greatly appreciate. Thanks in advance buddies.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
If you're using Bootstrap, this plugin[^] works really well.
There's also this one[^], which only requires jQuery.
Both are free and open-source.
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I am not familiar much with using the jquery libraries and I am sorry but I am not good in using built-in Java Script libraries like Kendo or from some other vendors etc.
I am writing my own JavaScript code.
Can you please help me in setting the value of the File upload when user selected the wrong file, it should either set to empty or "No file chosen" as it says in the begging, but Webforms file upload is showing the wrongly selected file in the file path box. Remaining script I was able to manage.
Can you please help me in this, any help like a code snippet, a link or even a suggestion helps me great. Thanks in advance buddy.
Like in the below function I need to set the value of the file upload to "No file chosen", if I try to set it up its not setting with value or val property.
<script type="text/javascript">
function CheckImageTypeAndSize() {
var aspFileUpload = document.getElementById("FileUpload1");
var errorLabel = document.getElementById("lbl_uploadMessage");
var img = document.getElementById("imgUploadThumbnail");
<pre>
var fileName = aspFileUpload.value;<br />
var fileSize; errorLabel.innerHTML = "";
try {
fileSize = aspFileUpload.files[0].size;
} catch (e) {
var objFSO = new ActiveXObject("Scripting.FileSystemObject");
var e = objFSO.getFile(aspFileUpload.value);
fileSize = e.size;<br />
}
var ext = fileName.substr(fileName.lastIndexOf('.') + 1).toLowerCase();
if (!(ext == "docx" || ext == "doc" || ext == "pdf")) {
errorLabel.innerHTML = "Invalid image file, must select a *.doc, *.docx, or *.pdf file.";
return false;
}
if (img.fileSize == -1) {
errorLabel.innerHTML = "Couldn't load doc file size. Please try to save again.";
return false;
}
else if (img.fileSize <= 2097152) {
errorLabel.innerHTML = fileName;
return true;
}
else {
var fileSize = (fileSize / 1048576);
errorLabel.innerHTML = "File is too large, must select file under 20 Mb. File Size: " + fileSize.toFixed(1).toString() + " Mb";
return false;
}
}
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
You can only do this if the client supports the relevant html5 apis. Google "html5 restrict file upload size" and you'll find examples on how to do this, it's a common request. For clients that don't support html5 you'll need to do the checks server-side after the file has already been uploaded.
|
|
|
|
|
How to filter data in DataTable using like operator ?
|
|
|
|
|
Do you mean filter the records exrtracted from your database?
|
|
|
|
|
|
Hi ,
i have a Fuel table with following fields :
ColumnName:
1.BillNo 2.BillDate 3.Amount 4.EmployeeId
1001 24.02.2015 1000 e101
1002 25.02.2016 586 e102
and also i bind the dropdownlist with employee tale with following fields
1.Employee Id(Selected value)
2.Employee Name(Display Value)
In My View I have DDL_Employee(dropdownlist) ,txt_fuel(textbox)
Now my question is While i am selecting DDL_Employee value(E101) Amount of 1000 will binidng in txt_Fuel
How to do this Task in Asp.Net Mvc, i am familiar with c# windows application, but here i am stuck in asp.net MVC ,
Give Any Suggestion
|
|
|
|
|
You have to use jquery change event on ddl. In the change event call action in your controller and retrieve the value and update it in textbox
|
|
|
|
|
Hi All,
I am storing a file into Database as Image type along with its extention in another column, I am giving a link button when user clicks on that button the file should be able to be downloaded in the same format as it is stored in database that's nothing but the type user has uploaded the file.
Any help is appreciated a code snippet, a link or even a suggestion is appreciated. Thanks you.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
If you store the file as a byte stream then it will download without any changes to its format.
|
|
|
|
|
Sure thank you.
Thanks,
Abdul Aleem
"There is already enough hatred in the world lets spread love, compassion and affection."
|
|
|
|
|
Hello,
I'm a beginner in the whole MVC thing.
I want to do a form where I get the user details by a user-dropdown-list in the same view.
Like, like (select *from users where username) is this possible on the same view and how?
I allready tried the MS tutorial but it doesnt help that much.
I'm Using the Entity framework with Database first.
Thank you
|
|
|
|
|
I need help please programmers, i need help i don't understand smtp.
____________________________________________
protected void Unnamed6_Click(object sender, EventArgs e)
{
MailMessage mailMsg = new MailMessage();
SmtpClient smtp = new SmtpClient();
try
{
mailMsg.From = new MailAddress(Email.Text);
mailMsg.To.Add("admin@mydomain.co.za");
mailMsg.IsBodyHtml = false;
mailMsg.Subject = "Contact Details";
mailMsg.Body = "Contact Details" + "<b>Name:</b>" + names.Text + " <br/> <b>Email - address :</b>" + Email.Text + "<br/> <b>Comments :</b>" + mgs.Text;
mailMsg.Priority = MailPriority.High;
smtp.Host = "localhost";
smtp.Port = 25;
smtp.Credentials = new System.Net.NetworkCredential();
smtp.Timeout = 25000;
smtp.EnableSsl = true;
smtp.Send(mailMsg);
lblStatus.Text = "Thank you. Your contact details and feed back has been submitted.";
}
catch (Exception ex)
{
lblStatus.Text = "Send Email Failed." + ex.Message;
}
}
---------------------------------------------------------------
Here is an output==
Send Email Failed.Failure sending mail.
|
|
|
|
|
smtp.Host = "localhost";
smtp.Port = 25;
Do you have an SMTP server running on your local system? If not then you will not be able to send any mail. Google for "ASP.NET SMTP" and you will find samples that show how to do it correctly.
|
|
|
|
|
@Richardd Thank for your help is brings confident. I did find Email-SMTP on IIS on my computer it running, but the message is not sending.
|
|
|
|
|
I use a tool called SMTP4DEV to catch SMTP messages. If the message makes it to the tool, the fault is not in the code but the configuration of the SMTP server.
Ah don't lean on me man, cause you can't afford the ticket
|
|
|
|
|
Is there a particular reason you are using smtp on your local machine? Use a known working smtp provider from your ISP\webhost\network admin and if the code works using that then the problem is how you've configured your smtp server, so is not a programming question.
|
|
|
|
|
I am working with ASP.NET MVC 4 using Visual Studio 2015 community edition, and IIS 8.. I am beginner in this technology..
I created login page,
In my Login controller (action Index), I put return RedirectToAction("Index", "Home") to redirect the page when users enter correct username and password.. it works when I debug/run it in visual studio environment.. but when I publish it (let say the name is MyPublishedWeb), create application in IIS, and browse it, the URL will look like this: localhost/MyPublishedWeb/Login/Index
The problem is when I login succesfully, it redirects me to localhost/Home/Index, instead of localhost/MyPublishedWeb/Home/Index, and it gives error..
But when I change RedirectToAction() to Redirect(), it work both in Visual Studio environment and IIS..
What do I miss?
Why RedirectToAction() doesn't work in IIS application?
|
|
|
|
|
Without knowing your routes, you can use "/" as the url as it normally defaults to Home/Index
|
|
|
|
|
I writing a project about product management. Now I want scan barcode of a product when I import/export to store. Can you help me?
|
|
|
|
|
|
|
Most scanners are fairly straightforward devices which read a barcode and return a string containing the actual product number. The issue you need to consider is where the scanner will be connected. If you are trying to do this into a website then how will the users get access to the scanner?
|
|
|
|
|
I'm having a hard time finding anything on this on the internet possible because I don't how to word the question properly.
So I'm reading the Chapter on Routing in Professional ASP.NET MVC 5 and on the second page they have a list of requirements for high-quality URLs. One bullet point is that a URL must be hackable, that is the end of the URL can be hacked off and still work. So I am currently adding handling for this into the controllers of a test project but I can't figure out how to do something.
For example, say I have a controller
public class DepartmentController : Controller {}
With a Details action
public ActionResult Details(int? id)
{
}
I did figure out out that by making the parameter nullable, the controller doesn't error when passed a URL like: http://www.somesite.com/Department/Details that is lacking a parameter therefore fulfilling the hackable requirement. My question is on handling it.
All of the examples I can find pretty much mirrors this:
public ActionResult Details(int? id)
{
if (id == null)
{
return RedirectToAction("FourOhFourError", "Errors", null);
}
else
{
{
}
What I would like to know how to do is to return nothing. Is there a way not to return a redirect or is that impossible with an HTTP GET (i.e. the server must return something to the client)?
I found this which, turns out, is the same as returning null:
return new EmptyResult();
but this just redirects the browser to an empty page. Is there a way to not do anything and have the browser stay on the same page or is that not how the HTTP protocol works?
if (Object.DividedByZero == true) { Universe.Implode(); }
|
|
|
|