By default, ASP.Net restricts the file uploaded to the server to be 4 MB. We can increase this setting in Web.Config through the tag. The below configuration setting is configured for all default values.
<httpRuntime executionTimeout="110" maxRequestLength="4096" requestLengthDiskThreshold="80" useFullyQualifiedRedirectUrl="false" minFreeThreads="8" minLocalRequestFreeThreads="4" appRequestQueueLimit="5000" enableKernelOutputCache="true" enableVersionHeader="true" requireRootedSaveAsPath="true" enable="true" shutdownTimeout="90" delayNotificationTimeout="5" waitChangeNotification="0" maxWaitChangeNotification="0" enableHeaderChecking="true" sendCacheControlHeader="true" apartmentThreading="false" />
To increase the default upload size, we need to increase the value of maxRequestLength property to whatever we want in KB. Default is 4096 KB(4MB).
To upload 100 MB, set maxRequestLength="102400"
Copy the above configuration inside tag in Web.Config.
this is the link
http://programming.top54u.com/post/ASP-Net-FileUpload-Size-Limit-Example.aspx
For Download:
just puts some logic here. which file u want to view and which file u want to download.
like
if file.extension=.jpg then view
if file.extension=.doc.....etc then download
other wise u put a button in right side which file u want to download;
use a link button name download in asp.net:
<asp:LinkButton id="download" Text="Download" runat="server" OnClick="download_Click" ForeColor="blue" ToolTip="Click here to download file" ></asp:LinkButton>
write code in c#:
protected void download_Click(object sender, EventArgs e)
{
string fileName = "";
fileName = System.IO.Path.Combine(giveHereFilePath, fileName);
DownloadFile(fileName,true); //call a method
}
private void DownloadFile(string fname, bool forceDownload)
{
//string path = MapPath(fname);
//string path = fname; System.IO.Path.Combine(ConfigReader.FilePath, "jewel.xls");
string name = System.IO.Path.GetFileName(fname);
string ext = System.IO.Path.GetExtension(fname);
string type = "";
// set known types based on file extension
if (ext != null)
{
switch (ext.ToLower())
{
case ".htm":
case ".html":
type = "text/HTML";
break;
case ".txt":
type = "text/plain";
break;
case ".doc":
case ".rtf":
type = "Application/msword";
break;
}
}
if (forceDownload)
{
Response.AppendHeader("content-disposition", "attachment; filename=" + name);
}
if (type != "")
Response.ContentType = type;
Response.WriteFile(fname);
Response.End();
}
Just Try in this way. Not exactly cause there are some spelling error may be but the logic is right.
If this helps you .
Please "Mark as Answer"
Ak_netchat, if this helps please login to Mark As Answer. | Alert Moderator