文件写在IIS服务器上,但下载不了。

core0 2016-08-18 04:49:00
#IF DEFINED PBWEBFORM THEN
ls_docname = "c:\temp\" + string(today(), 'YYMMDD') + '_' + string(now(), 'HHmmSS') + ".txt"
ll_value = 1
#ELSE
ls_cur_path = space(256)
getcurrentdirectorya(256, ls_cur_path)
ll_value = getfilesavename("导出文件", ls_docname, ls_named, "txt", "文本文件(*.txt), *.txt")
if ll_value = 1 then
setcurrentdirectorya(ls_cur_path)
end if

if fileexists(ls_docname) then
if messagebox('提示', ls_named + '文件已存在,需要覆盖吗?', Exclamation!, YesNo!, 2) = 2 then return
filedelete(ls_docname)
end if
#END IF

ll_value = FileOpen(ls_docname, LineMode!, Write!, LockWrite!, Append!)
for ll = 1 to dw_list.rowcount()
if dw_list.getitemnumber(1, 'flag') = 0 then continue
ls_str = dw_arg.getitemstring(1, 'code')
ls_str += ','
ls_str += dw_list.getitemstring(ll, 'invo_no')
ls_str += ','
ls_total = dw_list.getitemstring(ll, 'total')
if pos(ls_total, '.00') > 0 then ls_total = string(long(ls_total))
ls_str += ls_total
ls_str += ','
ls_str += string(date(dw_list.getitemstring(ll, 'invo_date')), 'yyyy-mm-dd')
ls_str += '~r'
filewrite(ll_value, ls_str)
next


#IF DEFINED PBWEBFORM THEN
fileclose(ll_value)
string s = GetDownloadFileUrl(ls_docname, false)
long ll_ = URLDownloadToFile(0, s, ls_docname, 0, 0)
if URLDownloadToFile(0, s, ls_docname, 0, 0) > 0 then messagebox('提示', '文件:' + ls_docname + ' 已导出。')
#ELSE
if fileclose(ll_value) = 1 then messagebox('提示', '导出完成。')
#END IF


怎么也下载不了,是GetDownloadFileUrl方法用错了吗?
...全文
2157 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
WorldMobile 2016-09-12
  • 打赏
  • 举报
回复
估计是虚拟目录引起的,给你段我写的代码,你参考一下





long ll_row, ll_value
string ls_suffix
ll_row = dw_main.getrow()
if ll_row <= 0 then
return
end if

string ls_file, ls_url, ls_path
string ls_name = "zgszh", ls_net = "zg_gctos"
ll_value = dw_main.getitemnumber(ll_row, "filevalue")
ls_suffix = dw_main.getitemstring(ll_row, "filesuffix")
ls_file = "myfile" + string(now(), "HHMMSS") + "." + ls_suffix
saveastype lenu_data, ld_data[]

ld_data[1] = Excel!
ld_data[2] = Text!
ld_data[3] = CSV!
ld_data[4] = SYLK!
ld_data[5] = WKS!
ld_data[6] = WK1!
ld_data[7] = DIF!
ld_data[8] = dBASE2!
ld_data[9] = dBASE3!
ld_data[10] = SQLInsert!
ld_data[11] = Clipboard!
ld_data[12] = PSReport!
ld_data[13] = WMF!
ld_data[14] = HTMLTable!
ld_data[15] = Excel5!
ld_data[16] = XML!
ld_data[17] = XSLFO!
ld_data[18] = PDF!
ld_data[19] = Excel8!
ld_data[20] = EMF!
ld_data[25] = XLSX!
ld_data[26] = XLSB!

lenu_data = ld_data[ll_value + 1]

#IF DEFINED PBWEBFORM THEN
if idw_data.SaveAs(ls_file, lenu_data, true) <> -1 then
ls_url = System.Web.HttpContext.Current.Request.Url.tostring()
ls_path = MapVirtualPath(ls_file)

long ll_pos, ll_next
ll_pos = pos(ls_url, "/" + ls_name + "/")
if ll_pos > 0 then
ls_url = left(ls_url, ll_pos - 1) + "/"

ll_next = pos(ls_path, ls_net + "_root")
if ll_next > 0 then
ls_url += mid(ls_path, ll_next)

ll_pos = pos(ls_url, '\')
do while ll_pos > 0
ls_url = left(ls_url, ll_pos - 1) + '/' + mid(ls_url, ll_pos + 1)
ll_pos = pos(ls_url, '\')
loop
shl_1.url = ls_url
end if
end if

ls_file = GetDownloadFileUrl(ls_file, false)
shl_2.url = ls_file

shl_1.visible = true
shl_2.visible = true
end if
#ELSE
idw_data.SaveAs(ls_file, lenu_data, true)
#END IF

kenshu 2016-08-22
  • 打赏
  • 举报
回复
用IE试试那个链接能不能下载。 看看有什么提示,比如权限不够之类的。 一些时候,也有可能只是文件类型不让下载,改一下IIS的设置就可以。

662

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder Web 应用
社区管理员
  • Web 应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧