General discussion


Open Word Doc using ASP.Net

By mrk_55 ·
Open Word doc using ASP.Net
I need help with code that allows you to open Word documents while using a ASP.Net 2003 web application form in windows 2003 server.

This conversation is currently closed to new comments.

1 total post (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Open With - MS Word

by jeff.cargill In reply to Open Word Doc using ASP.N ...

This is a chalenge. My work around. First, do an upload of the file to the server (code follows). Then do it again only this time right click on the file and open with. It may be a kludge but owell.

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient

Public Class UploadFile
Inherits Page
Protected WithEvents cmdUpload As Button
Protected lblInfo As Label
Protected WithEvents BrowseButton As System.Web.UI.WebControls.Button
Protected WithEvents FileInputTextBox As System.Web.UI.WebControls.TextBox
Protected WithEvents LabelInfo As System.Web.UI.WebControls.Label
Protected WithEvents File1 As System.Web.UI.HtmlControls.HtmlInputFile
Protected WithEvents Submit1 As System.Web.UI.HtmlControls.HtmlInputButton
Protected WithEvents dgrdViewDownloads As System.Web.UI.WebControls.DataGrid
Protected FileInput As HtmlInputFile

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub
Protected WithEvents Label2 As System.Web.UI.WebControls.Label
Protected WithEvents ReturnButton As System.Web.UI.WebControls.Button

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
End If
End Sub

Private Sub ReturnButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReturnButton.Click
End Sub

Private Sub Submit1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Submit1.ServerClick
If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
Dim fn As String = System.IO.Path.GetFileName(File1.PostedFile.FileName)
Dim SaveLocation As String = Server.MapPath("Data") & "\" & fn
Response.Write("The file has been uploaded.")
Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Dim conPubs As SqlConnection
Dim strInsert As String
Dim cmdInsert As SqlCommand
Dim str As String

str = ConfigurationSettings.AppSettings("SqlConnection")
conPubs = New SqlConnection(str)

strInsert = "INSERT issue_upload (issue_id, upload, created_by, creation_date, last_modified_by, last_modified_date) VALUES (@issue_id, @upload, @created_by, @creation_date, @last_modified_by, @last_modified_date)"
cmdInsert = New SqlCommand(strInsert, conPubs)
cmdInsert.Parameters.Add("@issue_id", Session("issueId"))
cmdInsert.Parameters.Add("@upload", fn)
cmdInsert.Parameters.Add("@created_by", Session("personId"))
cmdInsert.Parameters.Add("@creation_date", DateTime.Now())
cmdInsert.Parameters.Add("@last_modified_by", Session("personId"))
cmdInsert.Parameters.Add("@last_modified_date", DateTime.Now())

Catch Exc As Exception
Response.Write("Error: " & Exc.Message)
End Try
Response.Write("Please select a file to upload.")
End If
End Sub
Sub BindDataGrid()
Dim conPubs As SqlConnection
Dim dadViewDownloads As SqlDataAdapter
Dim dstViewDownloads As DataSet

conPubs = New SqlConnection(ConfigurationSettings.AppSettings("SqlConnection"))
dadViewDownloads = New SqlDataAdapter("SELECT ISSUE_UPLOAD.Upload AS Uploaded FROM ISSUE_UPLOAD WHERE issue_id = " & Session("IssueId") & " ORDER BY CREATION_DATE", conPubs)
dstViewDownloads = New DataSet

dgrdViewDownloads.DataSource = dstViewDownloads

End Sub
End Class

Back to Software Forum
1 total post (Page 1 of 1)  

Related Discussions

Related Forums