Here is my code in VB.Net
.aspx:
<input type="file"
style="width: 95%"runat="server"
id="inputFile" /> </td>
<td align="left" colspan="2"> <asp:button id="btnUpload"
Text=" Upload "
runat="server"
ToolTip="Click to upload file."
CssClass="Button">
</asp:button>
</td>
<td colspan="2">
<radU:RadProgressManager ID="RadProgressManager1" runat="server" UniquePageIdentifier="eae0adf1-8382-4884-8843-a38bf3b99b38" />
<radU:RadProgressArea ID="RadProgressArea1" runat="server">
</radU:RadProgressArea>
</td>
.aspx.vb
Protected Sub btnUpload_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpload.Click
'Store current user token in a variable...
Dim tokenCurrentUser As System.IntPtr = System.Security.Principal.WindowsIdentity.GetCurrent.Token
Try
file = RadUploadContext.Current.UploadedFiles(inputFile.UniqueID)
'validating
If validating() = False Then
Exit Sub
End If
fileName = file.GetName
fileExt = file.GetExtension
filesize = file.ContentLength
'Impersonate ASPNETRW account ...
Dim szASPNETRWPassword As String = Trim(All.DecryptPassWord(Trim(ConfigurationManager.AppSettings("ASPNETRWPassWord"))))
If Not ImpersonateUser.ImpersonateValidUser("aspnetrw", "HCA_LAN", szASPNETRWPassword) Then
'Notify user of error...
ClientScripts.CallMsgBox(
Me, "Error", "Sorry, unable to access archive at this time.")
Exit Sub
End If
file.SaveAs(ConfigurationManager.AppSettings(
"UploadFilePath") & fileName)
'update database
NewPHI_Request()
'send email notice
sendMail()
Response.Redirect("xThankyou.aspx", False)
Catch ex As Exception
Try
'pass error to web service...
xLogError.LogError(ex.Message, ex.StackTrace)
Catch exLogError As Exception
End Try
'place error message into session and redirect to error page...
Session.Item(
"ErrorMessage") = ex.Message.ToString()
Response.Redirect(
"xError.aspx", False)
Finally
'Set impersonation back to previous user...
ImpersonateUser.UndoImpersonation()
System.Security.Principal.WindowsIdentity.Impersonate(tokenCurrentUser)
End Try
End Sub