sorry i mean i save the path of the file in the database. somehow i don't know why it only saves the file without the changes made. I called my function of saving the path into the database only after i run my macro. Sorry, i've got a long code to explain but i just simply didnt know where to start. Sorry to have paste such a long code. My codes are as follows:
Saving the files into my directory:
For i = 0 To Request.Files.Count - 1 Step i + 1
objFile = Request.Files(i)
If objFile.FileName <> "" Then
strFileName = objFile.FileName
strFileName = strFileName.Substring(strFileName.LastIndexOf("\") + 1)
Try
objFile.SaveAs("d:\\upload\\" + strFileName)
strMessage += "Uploaded: " + strFileName + "<br>"
Catch err As Exception
strMessage += "Failed uploading " + strFileName + "::::::::" + err.ToString() + "*****<br>"
End Try
End If
Next
////////////////////////////////////////////////////////////////////////////////////////////////
My Macro Codes:
Dim objWordApp As New Word.ApplicationClass()
Dim objDOCFile = objWordApp.Documents()
objWordApp.ChangeFileOpenDirectory("D:\\upload\\")
objDOCFile.Open(FileName:=strFileName, ConfirmConversions:=False, ReadOnly:= _
False, AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:= _
"", Revert:=False, WritePasswordDocument:="", WritePasswordTemplate:="")
With objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection
'.WholeStory()
.TypeText(Text:="The ID Has Been Inserted. ")
End With
With objWordApp.ActiveDocument
If .ActiveWindow.ActivePane.View.Type = WdViewType.wdNormalView Or _
.ActiveWindow.ActivePane.View.Type = WdViewType.wdOutlineView Then
.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView
End If
.ActiveWindow.ActivePane.View.SeekView = .ActiveWindow.ActivePane.View.SeekView.wdSeekCurrentPageHeader '.wdSeekCurrentPageHeader
' .Selection.TypeText(Text:="This is header.")
objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection.TypeText(Text:="Epcos Pte Ltd")
objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection.TypeParagraph()
objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection.Find.ClearFormatting()
objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection.Find.Replacement.ClearFormatting()
With objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection.Find
.Text = "[\docu#\]"
.Replacement.Text = Label1.Text
.Forward = True
.Wrap = objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection.Find.Wrap.wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection.Find.Execute(Replace:= _
Word.WdReplace.wdReplaceAll) '(Replace:=objWordApp.ActiveDocument.ActiveWindow.ActivePane.Selection.Find..Wrap.wdReplaceAll)
End With
objWordApp.ActiveDocument.ActiveWindow.ActivePane.View.SeekView = objWordApp.ActiveDocument.ActiveWindow.ActivePane.View.SeekView.wdSeekMainDocument
objWordApp.ActiveDocument.SaveAs(strFileName, , _
LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword _
:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False)
objWordApp.Documents.Close()
objWordApp.Quit(Type.Missing, Type.Missing, Type.Missing)
Return strMessage
////////////////////////////////////////////////////////////////////////////////////////////////
Saving the path back to the database:
Dim iLength As Integer = CType(File1.PostedFile.InputStream.Length, Integer)
If iLength = 0 Then Exit Function 'not a valid file
Dim sContentType As String = File1.PostedFile.ContentType
Dim strMaxNo, i As Integer
Dim bytContent As Byte()
ReDim bytContent(iLength) 'byte array, set to file size
Dim cmdWA As SqlCommand
Dim dtrwa As SqlDataReader
'strip the path off the filename
Dim strFileName_New As String
strFileName_New = Request.QueryString("strFileName")
i = InStrRev(File1.PostedFile.FileName.Trim, "\")
If i = 0 Then
strFileName_New = File1.PostedFile.FileName.Trim
Else
strFileName_New = Right(File1.PostedFile.FileName.Trim, Len(File1.PostedFile.FileName.Trim) - i)
End If
Try
File1.PostedFile.InputStream.Read(bytContent, 0, iLength)
With cmdInsertAttachment
.Parameters("@FileName").Value = strFileName_New
.Parameters("@FileSize").Value = iLength
.Parameters("@FileData").Value = bytContent
.Parameters("@ContentType").Value = sContentType
.ExecuteNonQuery()
End With
Catch ex As Exception
'Handle your database error here
dbConn.Close()
End Try
////////////////////////////////////////////////////////////////////////////////////////////////
I Don't know why it didnt work. I'm sorry to have paste so a long code as i really really don't know where to start explaining........