Hyperlink does not react when click - asp.net

What I'm trying to do is to use hyperlink to redirect to local folder. The problem that I facing at the moment is the hyperlink seem to do nothing at all? Here are some of the method that I've tried:
1)
Dim FILEPATH As String = ("file:///D:/try/2019/" & id & "/")
HyperLink1.NavigateUrl = FILEPATH
2)
lblFileLink1.Text = " <a href='D:/HitoSensor_Attachment/2019/" & id & "/'>click</a> to see file"
3)
Dim FILEPATH As String = ("D:/try/2019/" & id & "/")
HyperLink1.NavigateUrl = FILEPATH
I've tried all these three yet the hyperlink react the same which is nothing. Is the problem with my hyperlink or is there anything else that I should fix?

Just do
Process.Start("ValidPath")

Related

double quote in text to create href doesn't work on vb.net

I have a problem to add the href into the Literal control. I spend an hour and didn't work on escape double quot. It shows the text instead of href. Would someone show me how to correct it.
There is my code:
dim id as integer=Cint(txtID.text.tostring())
dim href1 as string
Dim href1 As String = "<a target='_blank' class='body'" & "href='#'"
href = href & " onclick=""openWin('OrderForm/pop.aspx'?cId=" & id & "','',500,270);return false;"">" & Link & "</a>"
Dim ltLink As New Literal
ltLink.Text = href1
pnlLink.Controls.Add(ltLink)
Thanks in advance
Ideally, if you want to create markup at server-side, you want to use server control. It is less error prone than creating them manually.
Dim id As Integer = Convert.ToInt32(txtID.text.tostring())
Dim hyperLink = New HyperLink()
hyperLink.Target = "_blank"
hyperLink.CssClass = "body"
hyperLink.NavigateUrl = "~/OrderForm/pop.aspx?cId=" + id
hyperLink.Text = "Open Window"
hyperLink.Attributes("onclick") = "window.open(this.href, 'targetWindow', 'width=500,height=270');return false;"
pnlLink.Controls.Add(hyperLink)
I don't know what is openWin. I just assume you want to open a new windows. If it is a custom fuction, you can just replace mine with yours.

How to print a server side text file on a client printer programically

I have a server side application which creates a series of text files on the server. I need to allow a user to print one or more of the files directly on the client printer by clicking a button on a web page. That should bring up a printer selection window and then commence printing the selected web pages. I can handle the file selection and the printer selection windows but have not been able to get the files to print. I located code on Code Project (http://www.codeproject.com/Tips/689325/Send-PDF-files-directly-to-client-printer-without) which was described as doing exactly what I need but for for PDF files. I have attempted to adapt it to text files and the code runs without visible error, but nothing arrives at the printer and I do not know how to locate what happens after the code executes the value attribute of the Object tag of the web pages source code (see below). I program in VB.Net.
Here is the object tag in the source code:
<object id = "Object1" name="Txt1"
type="file/txt" width="1" height="1" >
<param name='SRC' value='<%= SReportFileName %>'/>
</object>
Here is the code from the code behind file:
Partial Class ViewResults_PrintingReports
Inherits System.Web.UI.Page
Public SReportFileName As String = ""
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim PathName As String = ""
Dim Uname As String = ""
Dim Iyr As String = ""
Dim Iwld As String = ""
Dim Iqtr As String = ""
Dim FName As String = ""
Dim CNumber As String = ""
Uname = "UserName"
Iyr = "3"
Iqtr = "1"
FName = "ReportA"
CNumber = "1"
Iwld = "1"
' Dim cs As ClientScriptManager = Page.ClientScript
PathName = "~/Competitions/" & Uname & "/BP/" & "World" & Iwld & "/Reports/QtrRpts" & Iwld & "." & Iyr & Iqtr & "/" & FName & "." & Iwld & CNumber & ".txt"
SReportFileName = PathName '// temp/mypdf.pdf
Try
ClientScript.RegisterStartupScript(GetType(Page), "MessagePopUp", "<script language=text/javascript>document.Txt1.printAll()</script>")
Catch ex As Exception
MsgBox("Problem printing file", , ex.Message)
End Try
End Sub
End Class
Any help would be appreciated.
You need to call javascript.
Here is the javascript
function PrintFile(FilePath) {
var printWin = window.open(FilePath, '','left=0,top=0,width=700,height=700,status=0');
printWin.focus();
printWin.print();
}
This is the codebehind of the button
Dim FilePath As String
FilePath = "This is your File Path"
Dim PrintFile As String
PrintFile = "PrintFile('" & FilePath & "')"
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ntmtch", PrintFile, True)

Get the parameter from the url of site using asp with vbscript

I have the code of Jquery for link to the asp page as below:
Jquery code:
var url = "script_right2.asp?soc="+societe+"&phoneNum="+phoneNumber+"&seleDro="+sedro+"&desc="+des;
I want to get the value of societe,phoneNumber,seleDro,desc to the page script_right2.asp
But the problem is that I do not know how to get these data in asp page using vbscript.
I'm not sure what the question is so I'll answer it twice!
To replicate what you have using VBScript:
dim stringUrl
stringUrl = "script_right2.asp?soc=" & societe & "&phoneNum=" & phoneNumber & "&seleDro=" & sedro & "&desc=" & des;
Or, if you want to get the value of the variables from the query string you could do
dim soc
dim phone
dim sedro
dim desc
soc = Request.QueryString("soc")
phone = Request.QueryString("phoneNum")
sedro = Request.QueryString("seleDro")
desc = Request.QueryString("desc")

how to get the remote url

I am using
Dim url As String = Server.MapPath("MyFiles") & "\" &
System.IO.Path.GetFileName(hpf.FileName)
to get the url of the uploaded file.
The result i get is
D:\2008VS\LTC INDIA\LTCIndia v 1.52\AdminPanel\MyFiles\1.jpg
i want it to be like this http://www.abcd.com/AdminPanel/MyFiles/1.jpg
Kindly let me know if posting the whole code would be of any help.
You could use the ResolveUrl method:
Dim url As String = ResolveUrl("~/MyFiles/" & System.IO.Path.GetFileName(hpf.FileName))

add client script to asp.net page dynamically

I want to add javascript to asp.net page dynamically.
can anybody point me towards working example?
i know it can be done by using Page.ClientScript.RegisterClientScriptBlock
but i have no idea to use it.
MSDN
This is the MSDN link
if (!this.Page.ClientScript.IsClientScriptBlockRegistered(typeof(Page), "Utils"))
{
string UtilsScript = ResourceHelper.GetEmbeddedAssemblyResource("Utils.js");
this.Page.ClientScript.RegisterClientScriptBlock(typeof(Page), "Utils", UtilsScript, true);
}
I added the above example to help,
Here we test if the script is already registered (using the type an dkey we register against) get the script as a string from an embedded resource, then register (the last parameter of true tells the code to render Script tags).
hope this helps
P
An example to move the value of a Drop Down List to text field. The ID parameters are the Object.ClientID properties for the drop down list and text box.
Private Sub RegisterClientDropDownToTextBox(ByVal functionName As String, ByVal dropDownId As String, ByVal textBoxId As String)
Dim javascriptFunction As String = "function " & functionName & "() {" & _
"document.getElementById('" & textBoxId & "').value = document.getElementById('" & dropDownId & "').value;" & _
"}"
Dim javascriptWireEvent As String = "document.getElementById('" & dropDownId & "').onclick = " & functionName & ";"
Me.ClientScript.RegisterClientScriptBlock(Me.GetType(), functionName & "_ScriptBlock", javascriptFunction, True)
Me.ClientScript.RegisterStartupScript(Me.GetType(), functionName & "_Startup", javascriptWireEvent, True)
End Sub

Resources