The next step is to remove the requirement for the sales manager to download and copy the Excel files. The easiest approach that is guaranteed to be supported for all sales notebooks is to create a basic ASP.NET upload page. ASP.NET allows uploads through the HtmlInputFile control. To allow a user-initiated upload, you need to take three steps:
Figure 16-9 shows the simple ASP.NET page used by the Graphic Design Institute. Figure 16-9. The ASP.NET upload page
The class code for the page is shown in Listing 16-15. The code reacts when the Upload button is clicked. It checks whether the file is valid (and not suspiciously large) and then transfers it to the location specified in the MonitorPath setting in the web.config file. The OrderProcessor then takes over the rest of the work. Listing 16-15 The ASP.NET upload page codePublic Class Upload Page Inherits System.Web.UI.Page Protected WithEvents FileUpload As HtmlInputFile Protected WithEvents FileInput As HtmlInputFile Protected WithEvents lblInfo As Label Protected WithEvents cmdUpload As Button Private Sub cmdUpload_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles cmdUpload.Click ' Check that a file is actually being submitted. If FileInput.PostedFile Is Nothing Then lblInfo.Text = "No file specified." Else If Not FileInput.PostedFile.FileName.EndsWith(".xls") Then lblInfo.Text = "You can only upload Excel files." ElseIf FileInput.PostedFile.ContentLength > 20000 Then lblInfo.Text = "The file is too large to be permitted." Else Try ' The saved file will retain its original file ' name, but be stored in the ExcelFiles directory. Dim SavePath As String SavePath = _ ConfigurationSettings.AppSettings("MonitorPath") SavePath &= "\" & Path.GetFileName( _ FileInput.PostedFile.FileName) ' Save the file. FileInput.PostedFile.SaveAs("E:\ExcelFiles\" & _ ServerFileName) lblInfo.Text = "File " & SavePath lblInfo.Text &= " uploaded successfully." Catch Err As Exception lblInfo.Text = Err.Message End Try End If End If End Sub End Class Alternatively, the ASP.NET page could perform the processing of the order file itself, by interacting directly with the component. However, we didn't choose this approach for a few reasons:
|