I am working on a form using old classic ASP. And this Classic ASP does not supports enctype=multipart/form-data . If I am using multipart/form-data then I am not getting any value after submitting the form. So please tell me how could i upload a image into a folder without using multipart/form-data. Any help will be appreciated.
Thanks in advance
i know the pain
check this out
http://www.codeproject.com/Articles/2359/File-Upload-using-a-VBScript-Class
if you want to acess other form elements use
Upload.Form("cmbtemp")
this might help you, if not tell me i will send you what i use for that
EDIT for code
form code
<form name="frmSend" method="POST" enctype="multipart/form-data" accept-charset="utf-8" action="upload_pdf.asp" >
and code for upload
function SaveFiles
Dim Upload, fileName, fileSize, ks, i, fileKey
DIM oufilename1,oufilename2,cmbtemp
Set Upload = New FreeASPUpload
Upload.SaveOne uploadsDirVar,0,oufilename1,oufilename2
cmbtemp=Upload.Form("cmbtemp")
'response.Write(cmbtemp)
if oufilename2 <> "" and cmbtemp <> "" then
con.execute "update tbltemp set file_name='"&oufilename2&"' where ID='"&cmbtemp&"'"
end if
' If something fails inside the script, but the exception is handled
If Err.Number <> 0 then Exit function
end function
this function called on post request
Related
Okay... I know having nested tags is not officially supported. But stay with me on this one..
I have an ASP.NET web page with the standard <form runat=server> tag at the top. I am pulling in a Form (and associated fields) from a 3rd party source via HttpWebRequest on the server side (code behind). I can verify the data I get contains a <form> tag -- via a Trace statement. Then I assign the data to my literal like this:
Dim objRequest As System.Net.HttpWebRequest = System.Net.WebRequest.Create(url)
Dim objResponse As System.Net.WebResponse
objRequest.Method = "POST"
Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData.ToString)
objRequest.ContentType = "application/x-www-form-urlencoded"
objRequest.ContentLength = byteArray.Length
Dim dataStream As Stream = objRequest.GetRequestStream()
dataStream.Write(byteArray, 0, byteArray.Length)
dataStream.Close()
objResponse = objRequest.GetResponse()
Dim streamRead As New StreamReader(objResponse.GetResponseStream())
Dim strResponse As String = streamRead.ReadToEnd()
me.litCMSForm.Text = strResponse
When the page is rendered, somehow .NET removed the <form> tag that was within the literal.
I also tried assigning the variable "strResponse" to a public variable to be displayed and it too had the tag stripped out. And I tried assigning the variable to an asp:Label as well with no luck. And I tried assigning the value to the literal on the "PreRender" function with no success.
Any thoughts on this and why .NET is stripping out the <form> tag?
Thanks!
You're correct - nested form tags are not supported. What you can do is generate JavaScript that would pass the string to an HTML container outside of ASP.NET form or, better yet, output it to an independent iframe.
I had the same problem. I was able to work around the situation by adding another form before the one I really wanted to insert. It seems like ASP was only frisky enough to strip out the first firm it found.
Perhaps this would work for you:
me.litCMSForm.Text = "<form name='fakeOut'></form>" + strResponse
I actually had my form code be a little fancier (I gave it an action and an hidden input). I didn't continue to test to see what could be taken away because it worked.
I am trying to render a hyperlink in an email template which will be sent to the user and if the user clicks on that link it will direct to a unique url. I have given the coding below,
email.AddMailmerge("RequestUrl", "Feedback Requests")
My problem is the link doesnt resolve correctly and take me to the right url. What am I doing wrong?
It resolves as:
C:\Users\Test\Desktop\localhost/Requests/Requests.aspx?Company_ID=KirprZ17bg5u5Qf1
Make sure you Appsetting contains http:// so instead of just
localhost
it needs to be
http://localhost
Be sure to format your href with quotes. Instead of relying on your app.config's value, which is return the C:\ value, use the .NET methods to get the current domain/URL.
Dim target As String = _
String.Format("<a href='{0}/Requests/Requests.aspx?Company_ID={1}'>Feedback Requests</a>",_
Request.Url.GetLeftPart(UriPartial.Authority),_
objCompany.IDHashed)
Dim strRequestLink As String = System.Configuration.ConfigurationManager.AppSettings("DomainName") & "/Requests/Requests.aspx?Company_ID=" & Me.ID & "&key=" & Me.IDHashed
Dim strRequestUrl As String = "http://" & strRequestLink & ""
I used the above formatting.
I'm having a problem with ASP.net redirection.
The Copy() method below is called from a javascript button in a grid with ajax and it works fine. It redirects to the Create action of the controller.
<AcceptVerbs(HttpVerbs.Post)> _
Sub Copy(ByVal noDemande As Integer)
Response.Redirect("/DemandeDeMontage/Create/" & noDemande)
End Sub
The Create action is a page that lets me edit the fields before saving them to the database. When an Id is passed, the fields will be pre-filled with another record's info (copied info).
<AcceptVerbs(HttpVerbs.Get)> _
Function Create(Optional ByVal id As Integer? = Nothing) As ActionResult
If (id Is Nothing) Then
Dim dmd As New DEMND_MONTG
Return View("Edit", dmd)
Else
Dim dmd As ODCT0124_DEMND_MONTG = _dmdMontRep.getDmdById(id)
dmd.CO_STAT = ModuleCommon.Status.AwaitingSave
Return View("Edit", dmd)
End If
End Function
There are no errors in the code above.
When debugging, everything seems to work. The Copy action is called, then Create, and then I can step through the HTML code of the Edit page without any errors.
However, the page will not change! It's like I'm not redirected at all. The edit page is not shown and I'm stuck on the page displaying the grid with all records I can copy.
Can someone explain why the edit page is not shown? Is there something really obvious I am not seeing?
That was a silly error on my part.
The Copy action was called via AJAX, but I forgot to specify what to do with the html returned from the action.
I'm using window.location = "/DemandeDeMontage/Copy/" + id now instead.
Could you please give your suggestions to the below problem:
I am working on a old project which was developed using traditional ASP and VB6.0.
I have registered the dll in component services. After creating the object in first line (in the code snippet below), when trying to call Login() method, it is giving the "Path not found" warning/error and I am not able to continue executing it further.
Thanks in advance for your consideration and help...also please let me know if you need more information...
SET objSecurity = Server.CreateObject( Application("APP_CLASS") & "Security" )
SET ox = new XMLTool
userID = uCase(userID)
dataXML = ""
IF objSecurity.Login( sessXML, userID, pwd, datXML ) Then
ox.LoadXML dataXML
..........
..........
"Path not found" is usually an IO exception. Does the objSecurity.Login() method read or write any data to a file or directory that does not exist? What is happening inside the objSecurity.Login() method?
Alternately, is there another "benign" method of the objSecurity object that you can call to verify that the object lives? Something like:
Dim sTest As String = objSecurity.Version()
or
Dim sTest As String = objSecurity.Name()
or even
Dim bExists As Boolean = (objSecurity IsNot Nothing)
I know that .ToString() didn't exist in VB6, but that's the idea.
Let's narrow down the problem to either objSecurity object itself, or something inside the .Login() method.
UPDATE:
Most of the answers given have just been some way of injecting the returned document into the html of the page, but this does not seem to be working. It might help if you could see what the aspx code is doing after all:
Try
RenderDocument = Session("docSelected")
If Not String.IsNullOrEmpty(Request.QueryString("download")) Then
asDownload = CBool(Request.QueryString("download"))
End If
If RenderDocument IsNot Nothing Then
Dim docBytes() As Byte
Dim docExtension As String = ""
Dim docFileSize As Long
GetBytesAndExtension(docBytes, docExtension, docFileSize)
If docBytes IsNot Nothing Then
Dim ms As New MemoryStream(docBytes)
With ms
Dim dataLengthToRead As Long = ms.Length
Dim blocksize As Integer
If dataLengthToRead >= 5000 Then
blocksize = 5000
Else
blocksize = dataLengthToRead
End If
Dim buffer(dataLengthToRead) As Byte
Response.Clear()
Response.ClearContent()
Response.ClearHeaders()
Response.BufferOutput = True
If asDownload = True Then
Response.AddHeader("Content-Disposition", "attachment; filename=" & RenderDocument.Name & "." & docExtension)
Else
Response.AddHeader("Content-Disposition", "inline; filename=" & RenderDocument.Name & "." & docExtension)
End If
Response.AddHeader("Content-Length", docFileSize.ToString())
Response.ContentType = "application/octet-stream"
While dataLengthToRead > 0 And Response.IsClientConnected
Dim lengthRead As Integer = ms.Read(buffer, 0, blocksize)
Response.OutputStream.Write(buffer, 0, lengthRead)
dataLengthToRead = dataLengthToRead - lengthRead
End While
Response.Flush()
Response.Close()
End With
Response.End()
Else
ResponseWithMessage("No Data")
End If
Else
ResponseWithMessage("No Document")
End If
Catch ex As Exception
ResponseWithMessage("ERROR: " & ex.Message)
End Try
What is the significance of the return type of the $.post() function? In my code I use 'html', but actually it could be a file being returned.
===================
ORIGINAL QUESTION:
The scenario is I want to load a html page which will call a specific ASP.Net script, this script returns a document based on some data stored in the session. It's function is irrelevant, essentailly it returns the document as an http response, however it may return one of several error strings depending on what has occured.
The html page shows a loading gif image and then when the document or error message is returned it needs to handle these appropriately.
I can get the page to display the error messages without a problem, but I don't know how best to handle the document request being returned, at the moment it just opens a new window and calls the url again, but that is clunky and calls the whole document retrieval process again (synchronously!) which defeats the purpose of using a nice ajax style load.
This is my JQuery code:
$(document).ready(function(){
$.post("displaydocument.aspx",null,function(data){
if (data == 'No Document'){
UpdateControls('No document has been specified to load');
}
if (data == 'No Data'){
UpdateControls('No data was found for that document');
}
if (data.indexOf('ERROR',0) != -1) {
UpdateControls(data);
}
window.open("displaydocument.aspx","doc");
window.close;
}
, "html");
});
function UpdateControls(message){
$("#txtInfo").html(message);
$("#imgLoading").hide();
}
This is my html:
<div style="text-align: center; font-family: 'Trebuchet MS';">
<img alt="loading" src="/images/loader64.gif" id="imgLoading" />
<br />
<span style="font-size: small" id="txtInfo">Document is loading...</span>
</div>
Your assistance is as always highly valued.
Thanks
Updated: I think the problem is that you are trying to do too much in one method. I would split it into two operations: check that the document is available and download the document. Have the method you call via POST (GET would work too since you aren't passing any data) do the existence check then create a link to a document handler URL that does the actual download. Add the link to the page and programmatically click it to invoke the download handler. The download handler would consist of your existing code and simply return an error page if invoked on a non-existent document. Note that the latter will not happen in normal operation, but could if someone bookmarked the downloaded document and it was removed.
Also, I'd be tempted to use JSON for the return value instead of HTML to make handling the error easier.
$(function() {
$.get('checkfordocument.aspx',null,function(data) {
if (!data.Success) {
UpdateControls(data.Message);
}
else {
UpdateControls('');
$("<a href='"
+ data.Url
+ "' target='_blank' class='docLink'>"
+ "Click here if your document does not start downloading</a>")
.appendTo('#txtInfo')
.trigger('click');
}
,'json');
});
Open your window and set it's contents using JS instead of sending another request to the server.
Instead of
window.open("displaydocument.aspx","doc");
do something like:
var win = window.open();
win.document.write(data);
This will set the contents of the new window without retrieving the data again.
I would create a web/wcf service who's responsibility is to notify you if a certain file exists. You could then return a simple json string with either a success flag and if it fails a relevent error message.
This also saves the need to request the file twice and you would also gain a reusable service for future pages & projects. I know the response for the document should be cached however the above functionality allows you to give greater error message notification to the user.
$.getJson('fileExistsService.svc', { filename : someName }, function(data){
if (data.success){
//open document
window.open("displaydocument.aspx","doc");
}
else {
//display error to use
//alert(data.errorMessage)
}
})