Server.map path not working in asp.net -
i using code download excel file exist in solution. have added folder fileupload , added excel file uploadcwf.xlsx. code workin in local host. not working when host server.i getting error - not find part of path. code -
string filepath = httpcontext.current.server.mappath("~/fileupload/"); string _downloadableproductfilename = "uploadcwf.xlsx"; system.io.fileinfo filename = new system.io.fileinfo(filepath + "\\" + _downloadableproductfilename); filestream myfile = new filestream(filepath + "\\" + _downloadableproductfilename, filemode.open, fileaccess.read, fileshare.readwrite); //reads file binary values binaryreader _binaryreader = new binaryreader(myfile); //check whether file exists in specified location if (filename.exists) { seek { long startbytes = 0; string lastupdatetiemstamp = file.getlastwritetimeutc(filepath).tostring("r"); string _encodeddata = httputility.urlencode(_downloadableproductfilename, encoding.utf8) + lastupdatetiemstamp; response.clear(); response.buffer = false; response.addheader("accept-ranges", "bytes"); response.appendheader("etag", "\"" + _encodeddata + "\""); response.appendheader("last-modified", lastupdatetiemstamp); response.contenttype = "application/octet-stream"; response.addheader("content-disposition", "attachment;filename=" + filename.name); response.addheader("content-length", (filename.length - startbytes).tostring()); response.addheader("connection", "keep-alive"); response.contentencoding = encoding.utf8; //send info _binaryreader.basestream.seek(startbytes, seekorigin.begin); //dividing info in 1024 bytes bundle int maxcount = (int)math.ceiling((filename.length - startbytes + 0.0) / 1024); //download in block of 1024 bytes int i; (i = 0; < maxcount && response.isclientconnected; i++) { response.binarywrite(_binaryreader.readbytes(1024)); response.flush(); } } grab (exception es) { throw es; } { response.end(); _binaryreader.close(); myfile.close(); } } else system.web.ui.scriptmanager.registerstartupscript(this, gettype(), "filenotfoundwarning", "alert('file not available now!')", true);
please 1 help me.
you should first concat filepath , filename path using server.mappath.
you should write code this
string filepath = httpcontext.current.server.mappath("~/fileupload/uploadcwf.xlsx"); system.io.fileinfo filename = new system.io.fileinfo(filepath);
asp.net
No comments:
Post a Comment