ADODB.Stream error '800a0bbc' Write to file failed - asp-classic

I've weird and strange error showing while I change hosting provider which is:
ADODB.Stream error '800a0bbc'
Write to file failed.
/cp/portal_upload.asp, line 63
I gave the needed permissions and it solve the update Access DB problem but file uploading still not fixed.
this is the code, thanks in advance:
Public Sub Save(path)
Dim streamFile, fileItem
if Right(path, 1) <> "\" then path = path & "\"
if not uploadedYet then Upload
For Each fileItem In UploadedFiles.Items
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = 1
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & fileItem.FileName, 2 'This is line 63
streamFile.close
Set streamFile = Nothing
fileItem.Path = path & fileItem.FileName
Next
End Sub

Firstly check if path & fileItem is a valid address?
If the folders is not created, create it.
Also, recheck your permissions. Have you given IUSR the permission of "Full Control"?

Related

Error when i upload file except txt ADODB.Stream error '800a0bbc'

error showing whenever I try to upload file except for txt, this error showing when I try upload jpeg file, there is no exception any specific file that can upload in the code, it should upload a jpeg file or pdf, but it showing error like this:
ADODB.Stream error '800a0bbc'
Write to file failed.
/ros/ROS/freeaspupload.asp, line 241
this is the freeaspupload code where the error came
Public Sub SaveParkir(path, prefixFile)
Dim streamFile, fileItem, i
if Right(path, 1) <> "\" then path = path & "\"
if not uploadedYet then Upload
i = 1
For Each fileItem In UploadedFiles.Items
Set streamFile = Server.CreateObject("ADODB.Stream")
streamFile.Type = 1
streamFile.Open
StreamRequest.Position=fileItem.Start
StreamRequest.CopyTo streamFile, fileItem.Length
streamFile.SaveToFile path & prefixFile & fileItem.FileName, 2
streamFile.close
Set streamFile = Nothing
fileItem.Path = path & prefixFile & fileItem.FileName
i = i + 1
'response.Write fileItem.Path
Next
'response.Write i
End Sub
what is the problem? how can i fix this? thanks in advance

System.Web.HttpException: The SaveAs method is configured to require a rooted path, and the path is not rooted

The error that I'm facing is :
System.Web.HttpException: The SaveAs method is configured to require a rooted path, and the path '~\FileUpload\2019\HS-123.png' is not rooted.
which I find is a bit weird since my code here:
Dim folderPath1 As String = ("~\FileUpload\" & Today.Year.ToString & "\")
If fileuploadSituation.HasFile Then
Dim extension As String = (Path.GetExtension(fileuploadSituation.FileName))
fileuploadSituation.SaveAs(Server.MapPath(folderPath1) & ID + extension)
End If
this code here work fine. But not this code:
If fileuploadSuggest.HasFile Then
Dim extension1 As String = (Path.GetExtension(fileuploadSuggest.FileName))
fileuploadSuggest.SaveAs(Server.MapPath(folderPath1) & ID + extension1)
End If
It work for the fileuploadSituation but not fileUploadSuggest even though they use the same path. Is there anything suggestion that I could use to apply?

When uploading image file onto my server from my webpage I want to display message if the upload timesout VB.net code behind

I check for file size and file extension already. But I still need to check if the upload process has timed out. If it does I want to display a message to the user that the upload timed out and they can try again later. Any help would be greatly appreciated! :)
Dim success As Boolean = False
Response.Write("*EIL*")
Try
If Not Context.Request.Files Is Nothing Then
Dim fileCount As Int32 = Context.Request.Files.Count
For fileLoop As Integer = 0 To fileCount - 1
Dim file As HttpPostedFile = Context.Request.Files(fileLoop)
Dim fileName As String
If file.ContentLength > 20971520 Then
Response.Write("The upload failed because the file size is too large - 20MB is the limit.")
Else
fileName = HttpUtility.UrlDecode(file.FileName)
Dim ext As String = fileName.Substring(fileName.Length - 4, 4).ToLower
If ext = ".jpg" Or ext = ".gif" Or ext = ".png" Or ext = ".bmp" Or ext = ".psd" Or ext = ".tif" Then
If InStr(fileName, "\") > 0 Then
Dim arr() As String = Split(fileName, "\")
fileName = arr(arr.Length - 1)
End If
file.SaveAs(String.Format(ConfigurationManager.AppSettings("ArtworkUploadPath"), fileName))
success = True
Else
Response.Write("The upload failed because the file was the wrong type. Only files with the following extensions are allowed: .jpg, .gif, .png, .bmp, .psd, .tif")
End If
End If
Next
If success Then Response.Write("Success")
End If
Catch ex As Exception
End Try
Short answer: you can't.
Longer answer: When an upload times out, it's because the server decides your code is taking too long, kills your process, and then throws an exception. Thus your code is no longer running when the timeout occurs, so there's no way to display a message to the user.
You can log the timeout if you want, as explained in a similar question.
Ideally, you don't want to catch the timeout anyway, you want to fix your page so it doesn't time out. You can do this a couple ways:
Change the value of maxRequestLength in your system.web to limit the allowed filesize, and show an error page to the user when their upload exceeds it.
Extend the timeout period by increasing the value of executionTimeout in your system.web, as in the answer found here.

I have path Manipulation issue. The following code is placed in Page_load method of ASPx page + VB

If Request.QueryString("ID") = "" Then
folderDirectory = Global.FileUpload.GetFolderDirectory(Request.QueryString("TFID"))
If Not File.Exists(folderDirectory + fileName) Then
If Not Directory.Exists(folderDirectory) Then
Directory.CreateDirectory(folderDirectory)
End If
Dim bufferSize As Integer = Me.fileUpload.PostedFile.ContentLength
Dim buffer As Byte() = New Byte(bufferSize) {}
' write the byte to disk
Using fs As New FileStream(Path.Combine(folderDirectory, fileName), FileMode.Create)
Dim bytes As Integer = Me.fileUpload.PostedFile.InputStream.Read(buffer, 0, bufferSize)
' write the bytes to the file stream
fs.Write(buffer, 0, bytes)
End Using
Else
CallOnComplete("error", "", "Error uploading '" & fileName & "'. File has been exists!")
Exit Sub
End If
But Fortify scan report for the above sample code shows Path Manipulation issue as high. I Need help to modify above code so that it can pass fortify scan
It is showing me error at folderDirectory
Usually, when your code works inside a web application you don't have the liberty to use the full file system as you do on your local PC. Any kind of 'Path Manipulation' is suspicious.
You should try to recode your works using Server.MapPath method.
Pay particular attention to this warning
For security reasons, the AspEnableParentPaths property has a default value set to FALSE.
Scripts will not have access to the physical directory structure unless AspEnableParentPaths
is set to TRUE.

asp fileExists always returning false

Trying to use a loop to check if images exists however it is always returning false. I am sure I am doing something simple and stupid but here is the code:
dim fs, sql_except
set fs=Server.CreateObject("Scripting.FileSystemObject")
if Not rs.eof then
arrRS = rs.GetRows(30,0)
set rs = nothing
If IsArray(arrRS) Then
For i = LBound(arrRS, 2) to UBound(arrRS, 2)
sku = arrRS(0, i)
if (fs.FileExists("../i/"&sku&".gif")=false) Then
response.write sku&"does not exist<br>"
end if
next
end if
erase arrRS
end if
set fs=nothing
You appear to be operating under the impression that the current folder context the your call to FileExists will assume is the physical folder containing the ASP script being executed. This is not so, it most likely will be "C:\windows\system32\inetsrv". You are also using URL path element separator / where FileExists is expecting windows physical path folder separator \.
You need to use Server.MapPath to resolve the path. This may work:
if Not fs.FileExists(Server.MapPath("../i/"&sku&".gif")) then
However you may run in to trouble with the parent path "..", this may not be allowed for security reasons. This might be a better approach:
Dim path : path = Server.MapPath("/parentFolder/i") & "\"
For i = LBound(arrRS, 2) to UBound(arrRS, 2)
sku = arrRS(0, i)
if Not fs.FileExists(path & sku & ".gif") Then
response.write Server.HTMLEncode(sku) & " does not exist<br>"
end if
next
Where "parentFolder" is the absolute path from the site root.

Resources