Path.GetFileName() returns the file name.
Response.AppendHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(filename))
Reference documentation.
Or maybe the ChildNode1 variable contains the file name?
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am downloading the file using the below code. But, downloading the file is showing the full path of the filename.
Example :
Filaname : Test.asd
File path : \tdsment.tds.intranet\USA\PART1\2022\
current download file (after downloading) : _tdsment.tds.intranet_USA_PART1_2022_Test.asd
I don't want to show the full file path after downloading the file.
Simply my downloaded file should be "Test.asd"
It means Expecting download file name : Test.asd
Public Sub TreeView1_SelectedNodeChanged(sender As Object, e As EventArgs)
Dim ChildNode1 As String = TreeView1.SelectedValue
filename = GetFileName(ChildNode1)
Response.Clear()
Using oBinaryReader As BinaryReader = New BinaryReader(File.OpenRead(filename))
Response.ContentType = "application/octet-stream"
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filename)
Response.TransmitFile(filename)
Response.Flush()
End Using
End Sub
Private Function GetFileName(ChildNode1 As String) As String
filepath = "\\tdsment.tds.intranet\USA\PART1\2022\"
Dim Result As String
Result = String.Concat(filepath, ChildNode1)
Return Result
End Function
Path.GetFileName() returns the file name.
Response.AppendHeader("Content-Disposition", "attachment; filename=" + System.IO.Path.GetFileName(filename))
Reference documentation.
Or maybe the ChildNode1 variable contains the file name?
Hi @BeUnique ,
If you don't have the full path route, you can't download the file. So, your requirement can't be realized. You could rename the filename. As your codes, rename the filename same as "ChildNode". So , Please delete "String.Concat".
Best regards,
Yijing Sun
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.