unable to upload the pdf document in .net 2.0 and getting exception error - visual-studio-2005

I have developed a application where i am uploading the PDF files and binding it to Gridview. I can upload less size files like up to 3.5MB after that i can not upload PDF file as i get error message like "Server Error in '/STAT' Application. Runtime Error" or "Page can not be displayed (while testing in local system)"
Technologies used :
vs 2005
.net 2.0 and it is web application.
I have pasted the code below which i wrote :
Protected Sub btnUploadSTPI_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUploadSTPI.Click
Try
If txtStpiRegNo.Text <> "" Then
If txtfilepathSTPI.Value <> "" Then
Dim objDS As DataSet
Dim UploadFile, UploadPath, strFile, sUploadPath, sUploadfilename As String
Dim arr As Array
UploadFile = txtfilepathSTPI.Value
UploadPath = UploadFile.LastIndexOf("\") + 1
strFile = UploadFile.Substring(UploadPath)
sUploadPath = System.Configuration.ConfigurationSettings.AppSettings("UploadTempFile").ToString()
arr = strFile.Split(".")
strFile = CType(arr(0).ToString() + "_" + txtStpiRegNo.Text + "_" + System.DateTime.Now.Second.ToString() + "." + arr(1).ToString, String)
sUploadfilename = sUploadPath + strFile
txtfilepathSTPI.PostedFile.SaveAs(sUploadfilename)
objDS = Session("TempDS")
If objDS.Tables.Count > 1 Then
Dim objRow As DataRow
objRow = objDS.Tables(1).NewRow()
objRow.Item("UploadFileName") = arr(0).ToString()
objRow.Item("UploadFilePath") = strFile
objRow.Item("CompanyID") = ddlCompany.SelectedValue
objRow.Item("CompanyDocuments") = "STPI REG NO - " + txtStpiRegNo.Text
objDS.Tables(1).Rows.InsertAt(objRow, objDS.Tables(1).Rows.Count + 1)
dgCompanyFiles.DataSource = objDS.Tables(1)
dgCompanyFiles.DataBind()
Session("TempDS") = objDS
End If
Else
lblError.Text = "Please select a file to upload."
End If
Else
lblError.Text = "Please enter STPI REG No."
End If
Catch ex As Exception
End Try
End Sub
Even I tried tracking the application and it is not going to the particular button event after browsing the file and clicking on the Upload button for larger file size more then 3.5MB..
Error Message :
Server Error in '/STAT' Application.
Runtime Error
Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for security reasons). It could, however, be viewed by browsers running on the local server machine.
Details: To enable the details of this specific error message to be viewable on remote machines, please create a tag within a "web.config" configuration file located in the root directory of the current web application. This tag should then have its "mode" attribute set to "Off".

First, you need to edit web.config to enable viewing errors. The method for doing this is displayed in the reported error itself.
Second, you need to allow larger upload file sizes:
<configuration>
<system.web>
<httpRuntime maxRequestLength="xxx" />
</system.web>
</configuration>

Related

Microsoft Access 2019 Report. Automatically Resize Image Control

Insert and resize a picture in an access report
Solution by Ms Isabel Smit aborts at first line of code.
My Report textbox [P1] populated by query has links to *.jpg files.
But code, Me.Image46.Picture = Me.P1.Value does not work. Get error msg Run-time error '94': Invalid use of Null.
Neither does Me!Image46.Picture = Me![P1] Run-time error '13': Type mismatch
Neither does Me!Image46.Picture = Me![P1].Value
Works if Me!Image46.Picture = hard coded filename but it defeats objective of each record to link to different filename.
Thank you
Updated Solution with validation:
I built your form and tested it. The only time I got it to fail was when the path to the image was invalid. Please try this:
Dim strFilename As String
strFilename = Me![P1].Value
If Len(Dir(strFilename)) > 0 Then
Me![Image7].Picture = strFilename
Me![Image7].Height = 9666 * Me![Image7].ImageHeight / Me![Image7].ImageWidth
Me![Image7].Width = 9666
Else
MsgBox "Image not found"
End If

Errors Loading a Network File into a Stream in Classic ASP

I have a Classic ASP website that currently loads PDF files from a local directory and writes them to the Response. I create a stream and use LoadFromFile to pull the data. This has worked well for years, but we now want to delete the local files and pull from a network "\" drive, where all of our .NET sites pull the files from.
We do this in our .NET sites with no problem, but I cannot figure out how to open a network file from Classic ASP and load it into a stream. Nothing I have tried seems to recognize the "\server\directory\file" as a valid path.
So, just to be as clear as possible, this is what we do:
Pull a DocID from the QueryString.
Pass the DocID as a parameter to a SQL proc to pull the path to the file (In the current ASP page it pulls a local path, in .NET it pulls a network path. In our new ASP page it will now pull a network path).
We create a stream and load the file into it (this is the part that does not work in Classic ASP if the path is "\" instead of "D:\").
We change the Response.ContentType to "application/pdf".
We Response.BinaryWrite and Flush the Response.
The result is the page displays the PDF with no indication of the file name or location.
Adding partial code:
' sets the Cache-Control HTTP header to prevent proxy caching
Response.CacheControl = "Private"
Response.Expires = 0
Response.Buffer = True
Response.Clear
sDocID = Request.QueryString("DocID")
sSQL = "exec Get_DocData '" & sDocID & "'"
Set rsDoc = Server.CreateObject("ADODB.RecordSet")
rsDoc.Open sSQL, conn, 3, 1
'
' sPath = \\server\directory\filename.ext
' sFileName = filename.ext
'
sPath = rsDoc.Fields("DocPath").Value
sFileName = rDoc.Fields("DocDescription").Value
rsDoc.Close
Set rsDoc = Nothing
'sPath = Replace(sPath,"\\<svr>\<dir>","Z:")
If sPath <> "" Then
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1 ' adTypeBinary
oStream.LoadFromFile sPath
Response.ContentType = "application/pdf"
Response.AddHeader "Content-Disposition", "inline; filename=""" & sFileName & """"
Response.Charset = "UTF-8"
Do while not oStream.EOS
Response.BinaryWrite oStream.read(3670016)
Response.Flush
Loop
oStream.Close
Set oStream = Nothing
Else
Response.ContentType = "text/html"
'Response.Write("Invalid Document ID.")
End If
Response.End
Well, I knew I would feel stupid when I figured this out. As Lankymart commented, the LoadFromFile() does support UNC formatted paths, which lead me to suspect the issue was permission-based and not code-based.
Although our ApplicationPool was running under a general account which had permission to the network drives, the site was not. I simply brought up the site in IIS7, clicked on Basic Settings and used the "Connect as..." button to run the site under the same general account. That corrected my issue. Palm-slapping my head.

Lotus Notes - Web form agent - not sending email

I have a web form that when the button is pressed should pull a list of names from a field and send a mail. The mail isn't sending.... Here is the lotus script... thanks in advance
Sub Click(Source As Button)
Dim s As New NotesSession
Dim ws As New NotesUIWorkspace
Dim db As NotesDatabase
Dim view As NotesView
Dim doc As NotesDocument
Dim mdoc As NotesDocument
Dim ddoc As NotesDocument
If ws.CurrentDocument.IsNewDoc Then
Call ws.CurrentDocument.Save
Set db = s.CurrentDatabase
Set view = db.GetView("deptLookup")
Set doc = ws.CurrentDocument.Document
dept$ = doc.ProcDeptAssoc(0)
Set ddoc = view.GetDocumentByKey(dept$)
If ddoc Is Nothing Then
Msgbox "Department not found"
Else
Set mdoc = New NotesDocument(db)
mdoc.Subject = "Comment made on procedure " + doc.ProcNo(0) +" - "+doc.ProcName(0)+ " by " + doc.CreatedBy(0)
Dim rtitem As New NotesRichTextItem(mdoc, "Body")
Call rtitem.AppendText("Requires the approval of " +doc.approver(0)+", click the link and the approve or deny the request. ")
Call rtitem.AddNewline(1)
Call rtitem.AppendDocLink(doc, "CommentsDoc")
receipients = ddoc.NotifyName
mdoc.SendTo = receipients
mdoc.Send(False)
End If
Else
Call ws.CurrentDocument.Save
End If
ws.CurrentDocument.Close
End Sub
If you use a form instead of an XPage you will need to place your code in the agent and set that agent as WebQuerySave agent of the form. LotusScript under the button will not run when accessed from the web.
Also you cannot use UI classes like NotesUIWorkspace in backend code.
You can move that Lotusscript code to an agent with trigger "agent list selection" and target "none" and from the web form to use a #formula (not lotusscript) button with this #command:
#Command([RunAgent];"NAME_OF_YOUR_AGENT");
Panu Haaramoroperties is right when he says than the Lotusscript click event in buttons doesn't works from web forms but #commands do work.
He es also right when he said the you have to replace NotesUIWorkspace reference. You can begin using :
s.documentContext
instead
ws.CurrentDocument

How do I display an image from Sql Server with Microsoft Access?

I upsized an Access 2007 database to SQL Server 2008 R2. The images are in SQL Server as image type. Access has link to the table containing the image. When I try to display from within Access, it won't do it. It still has the OLE Object wrapper.
How can I get that image and display it on my forms in Access? I do not have the option, at the moment, to remove the images, put them in a directory and point to them (the best way I know but not an option). I need to read the image / blob file directly from SQL Server and display it on an Access form.
Thank you for any ideas.
I saw this but it did not help:
How to display image from sql server in ms access
http://access.bukrek.net/documentation looks like the file in folder method
Since Access 2010, you can use the PictureData property to store and display images from SQL Server. You will need a bound control for an SQL Server data type varbinary(max), which can be hidden, and an unbound Image control in MS Access. You can now simply say:
Private Sub Form_Current()
Me.MSAccessImageControl.PictureData = Me.SQLServerImage
End Sub
And vice versa. You will need to add some error management to that, but very little else.
Below is a function I have successfully used called BlobToFile. And I also posted the code that I use to test it. The picture gets dumped to a so-called temp file but its not truly temp because it isn't in the temp directory. You can manually delete the image file or else you'll have to write it to your temp folder instead. Then I have an image control where I display the picture.
Private Sub Command1_Click()
Dim r As DAO.Recordset, sSQL As String, sTempPicture As String
sSQL = "SELECT ID, PictureBlobField FROM MyTable"
Set r = CurrentDb.OpenRecordset(sSQL, dbSeeChanges)
If Not (r.EOF And r.BOF) Then
sTempPicture = "C:\MyTempPicture.jpg"
Call BlobToFile(sTempPicture, r("PictureBlobField"))
If Dir(sTempPicture) <> "" Then
Me.imagecontrol1.Picture = sTempPicture
End If
End If
r.Close
Set r = Nothing
End Sub
'Function: BlobToFile - Extracts the data in a binary field to a disk file.
'Parameter: strFile - Full path and filename of the destination file.
'Parameter: Field - The field containing the blob.
'Return: The length of the data extracted.
Public Function BlobToFile(strFile As String, ByRef Field As Object) As Long
On Error GoTo BlobToFileError
Dim nFileNum As Integer
Dim abytData() As Byte
BlobToFile = 0
nFileNum = FreeFile
Open strFile For Binary Access Write As nFileNum
abytData = Field
Put #nFileNum, , abytData
BlobToFile = LOF(nFileNum)
BlobToFileExit:
If nFileNum > 0 Then Close nFileNum
Exit Function
BlobToFileError:
MsgBox "Error " & Err.Number & ": " & Err.Description, vbCritical, _
"Error writing file in BlobToFile"
BlobToFile = 0
Resume BlobToFileExit
End Function

Migrate Web Services (VS2003) to WCF (VS2010)

Our site is maintained with VS2003. We converted our solution to VS2010--it is a Web Application Project. It has several Web Services files (.asmx file endings) that we hoped to convert to WCF in two stages, first preserve the function of the asmx files that write back XML documents via AJAX to the client..., and then learn to build AJAX-enabled WCF Services to do the same things.
We have researched the 'Could not create type xxx'-error and the advice varies. We're certain(!!) that having an App_Code folder is not the difference, and that we've named our namespace and class correctly, and that we've decorated the Web Service code correctly, and that we're able to use ASP.Net 2.0 to activate these services, and that we have the application level set correctly in IIS... and we're still not able to get past the error.
Here is our asmx code (we created a test page with ScriptManager control to try to hit this one Web Method, but we never got past the build for the service). You certainly don't need to bother with the actual database pulls, but I left them in anyway:
Imports System
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
Imports System.ComponentModel
Imports System.Data.SqlClient
Imports System.Text
Imports System.Uri
Imports System.Xml
Imports System.IO
<WebService([Namespace]:="nsCarousel", Description:="Carousel Web Service Methods")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _
Public Class Carousel
Inherits WebService
<WebMethod(Description:="Get Dealer Info")> _
Public Function GetDealerInfo(ByVal DID%) As String
Dim s$, sql$, sRequest$, sRequestPathQuery$, sDID$, sAJAX$, sReturn$, sIP$, sWebSite$, sErr$, sDealerSearch$
Dim sXML$, sXMLDealerResults$, sXMLPath$
Dim sUserName$, sGeneralDesc$, sStatusText$
Dim bPost As Boolean
Dim bHaveData As Boolean
Dim ds As DataSet
Dim dasql As SqlDataAdapter
Dim sqldr As SqlDataReader
Dim sqlConn As SqlConnection
Dim sqlCmd As SqlCommand
Dim xdoc As New XmlDocument
Dim xnode As XmlNode
Dim xrefnode As XmlNode
Dim xnewnode As XmlElement
Try
'/ need test of sRequest for reference and use in test just below
bPost = False
sDID = Convert.ToString(DID)
sGeneralDesc = "Dealer Pull"
sqlConn = New SqlConnection(ConfigurationSettings.AppSettings("ConnectionStringLong"))
sqlConn.Open()
'/ new sp to preserve nodes, even when fields are null
'/ get results for individual dealer
sql = "insert into junk(entrydate, sql_stmts) select GetDate(), '" & sDID & "';"
sqlCmd = New SqlCommand(sql, sqlConn)
sqlCmd.ExecuteNonQuery()
sqlCmd.Dispose()
sql = "Select_DRPROByDID_xml " & sDID
sqlCmd = New SqlCommand(sql, sqlConn)
sqldr = sqlCmd.ExecuteReader()
'/ quick test if have data
bHaveData = False
Do While sqldr.Read
If Not (IsDBNull(sqldr("DNum"))) Then
bHaveData = True
End If
Exit Do
Loop
sqldr.Close()
sqldr = Nothing
sqlCmd.Dispose()
sqlCmd = Nothing
'/ s will include a node for NewDataSet -> remove and add nodes for msg based on status
'/ and DealerError
If bHaveData Then
dasql = New SqlDataAdapter(sql, sqlConn)
ds = New DataSet
dasql.Fill(ds)
s = ds.GetXml
sXMLDealerResults = s
dasql.Dispose()
ds.Clear()
dasql = Nothing
ds = Nothing
'/ query the XML doc
xdoc.LoadXml(s)
xnode = xdoc.SelectSingleNode("/NewDataSet/Table")
If (xnode.HasChildNodes) Then
If (sDID.Length > 0) Then
sStatusText = xdoc.GetElementsByTagName("DRStat").Item(0).InnerText
Select Case sStatusText
Case "A"
'/ test next when opportunity exists
'/ set current node at Table
'sXMLPath = "/NewDataSet/Table"
'/ set Table as the current node
'xrefnode = xdoc.SelectSingleNode(sXMLPath)
'xnewnode = xdoc.CreateElement("DealerMsg")
'sStatusText = "Active dealer found."
'xdoc.InsertAfter(xnewnode, xrefnode)
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerMsg>Active dealer found.</DealerMsg>")
Case "C"
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerMsg>Dealer has been cancelled.</DealerMsg>")
Case "H"
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerMsg>Dealer is on hold.</DealerMsg>")
Case Else
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerMsg>Dealer status is invalid.</DealerMsg>")
End Select
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerError>1</DealerError>")
Else
'/ do nothing
End If
Else
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Table><DealerError>0</DealerError><DealerMsg>Dealer not found.</DealerMsg>")
End If
Else
sXMLDealerResults = "<Table><DealerError>0</DealerError><DealerMsg>Dealer not found.</DealerMsg></Table>"
End If
sXMLDealerResults = sXMLDealerResults.Replace("<NewDataSet>", "")
sXMLDealerResults = sXMLDealerResults.Replace("</NewDataSet>", "")
If (sDID.Length > 0) Then
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "")
sXMLDealerResults = sXMLDealerResults.Replace("</Table>", "")
Else
sXMLDealerResults = sXMLDealerResults.Replace("<Table>", "<Dealer>")
sXMLDealerResults = sXMLDealerResults.Replace("</Table>", "</Dealer>")
End If
sXML = "<?xml version=""1.0"" ?><DealerFetch>" + sXMLDealerResults.Trim + "</DealerFetch>"
'If sReturn.Trim.Length = 0 Then
' Response.ContentType = "text/xml"
' Response.Write(sXML)
'End If
sqlConn.Close()
sqlConn = Nothing
Return sXML
Catch exp As Exception
sErr = sErr & " " & exp.Message.ToString
End Try
End Function
End Class
Any help would be appreciated. Maybe it's something obvious that will appear to someone here quickly, but it sure is making us fret!!! If you need more info or code, please let us know.
There are tons of good samples and demos how to achieve this.......
Just a few a quick Google search turned up:
Convert existing asmx .net web service to WCF service in .net 3.0/3.5
Convert .asmx file to WCF .svc file to create simple API web service
Migrating a Versionable ASMX Web Service to WCF
I would just search Google for your keywords (ASMX, WCF, Migrate) and you should get tons of links and useful resources.....
As for resources to learn the basics of WCF: there's the MSDN WCF Developer Center which has everything from beginner's tutorials to articles and sample code.
Also, check out the screen cast library up on MSDN for some really useful, 10-15 minute chunks of information on just about any topic related to WCF you might be interested in.

Resources