TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
narasappa J
NA
147
3.2k
show progress bar while downloading pdf from FTP on web appl
Nov 17 2017 5:09 AM
I am trying to download files from FTP. The requirement is to show a progress bar with Downloadingsize/Filesize and percentage.
I am able to display progress bar on Windows Form Application but On web application hosted on Local IIS server, I am getting a problem. I am using below code to download files from FTP on generic handler
public
bool
DownLoadFilesFromFTp(
string
fileName,
string
ftpFolder)
{
//Create FTP Request.
try
{
string
Ftp_Host = System.Configuration.ConfigurationManager.AppSettings[
"Ftp_Host"
];
string
Ftp_UserName = System.Configuration.ConfigurationManager.AppSettings[
"Ftp_UserName"
];
string
Password = System.Configuration.ConfigurationManager.AppSettings[
"Password"
];
string
downloadpath= System.Configuration.ConfigurationManager.AppSettings[
"downloadpath"
];
//Fetch the Response and read it into a MemoryStream object.
string
ftpurl = Ftp_Host + ftpFolder +
"/"
+ fileName;
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(
new
Uri(ftpurl));
reqFTP.Credentials =
new
NetworkCredential(Ftp_UserName, Password);
reqFTP.KeepAlive =
false
;
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary =
true
;
reqFTP.Proxy =
null
;
reqFTP.UsePassive =
false
;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream responseStream = response.GetResponseStream();
FileStream writeStream =
null
;
writeStream =
new
FileStream(downloadpath + fileName, FileMode.Create);
int
Length = 2048;
// 2048;
Byte[] buffer =
new
Byte[Length];
int
bytesRead = responseStream.Read(buffer, 0, Length);
while
(bytesRead > 0)
{
writeStream.Write(buffer, 0, bytesRead);
bytesRead = responseStream.Read(buffer, 0, Length);
}
responseStream.Close();
writeStream.Close();
response.Close();
return
true
;
}
catch
(WebException wEx)
{
return
false
;
}
catch
(Exception ex)
{
return
false
;
}
}
public
void
ProcessRequest(HttpContext context)
{
DownLoadFilesFromFTp(
"FileName.pdf"
,
"Foldername"
);
}
class
=
"progress CustomProgress"
>
"FileProgress"
class
=
"progress-bar"
role=
"progressbar"
aria-valuenow=
"0"
aria-valuemin=
"0"
aria-valuemax=
"100"
style=
"width: 0%;"
>
>
$(
"#MainContent_btnDownload"
).click(
function
() {
$.ajax({
type:
"POST"
,
url:
"Downloader.ashx"
,
success:
function
(data) {
//alert(data);
}
});
});
I want to add below progress listener on my above ajax call
function
progressHandlingFunction(e) {
var
TotalFileSize = GetFileSize( e.total);
if
(e.lengthComputable) {
$(
"#FileProgress"
).show();
var
percentComplete = Math.round(e.loaded * 100 / e.total);
$(
"#FileProgress"
).css(
"width"
, percentComplete +
'%'
).attr(
'aria-valuenow'
, percentComplete);
$(
'#FileProgress span'
).text(percentComplete +
"%"
);
$(
"#progressreport"
).html(
"Uploading "
+ GetFileSize(e.loaded) +
" of "
+ TotalFileSize);
}
else
{
$(
'#FileProgress span'
).text(
'unable to compute'
);
}
}
How can call this function on ajax request
Reply
Answers (
1
)
How to call Javasrcipt fuction in label tag with paramaters
Invalid postback or callback argument