Click here to Skip to main content
15,887,827 members
Home / Discussions / ASP.NET
   

ASP.NET

 
GeneralRe: port forwarding on mobile Pin
Debojyoti Saha19-Oct-15 2:55
professionalDebojyoti Saha19-Oct-15 2:55 
GeneralRe: port forwarding on mobile Pin
Member 1191972219-Oct-15 19:53
Member 1191972219-Oct-15 19:53 
GeneralRe: port forwarding on mobile Pin
Member 1191972219-Oct-15 20:30
Member 1191972219-Oct-15 20:30 
Questionangular js and asp.net mvc Pin
Arjun Mourya15-Oct-15 20:31
Arjun Mourya15-Oct-15 20:31 
QuestionIs there any way to avoid writing store procedure for 30 columns. Pin
Praveen Kandari15-Oct-15 1:40
Praveen Kandari15-Oct-15 1:40 
AnswerRe: Is there any way to avoid writing store procedure for 30 columns. Pin
ZurdoDev15-Oct-15 2:12
professionalZurdoDev15-Oct-15 2:12 
GeneralRe: Is there any way to avoid writing store procedure for 30 columns. Pin
Praveen Kandari15-Oct-15 2:19
Praveen Kandari15-Oct-15 2:19 
QuestionMake uploading of file optional?? Pin
samflex13-Oct-15 9:56
samflex13-Oct-15 9:56 
Greetings gurus,

This problem has bugged me down all day.

The subs below allow our users the ability to save a file to the server and filename and path to the database.

This works great except that management doesn't want users forced to upload a file if they don't want to.

In other words, uploading of a file should be optional, not required.

So far, I have tried several different things to remove only the part that challenges users to upload a file before record is saved.

I have also tried googling for easier solutions but have found none yet.

Any assistance is greatly appreciated.

Protected Sub Btn_Click(ByVal sender As Object, ByVal e As EventArgs)
    Dim btn As LinkButton = DirectCast(sender, LinkButton)
    Dim savecontinue As String = btn.CommandArgument    
    Dim correctExtension As Boolean = False
    'Dim blSucces As Boolean = False
    Dim FilePath As String = ConfigurationManager.AppSettings("FilePath").ToString()

    If FileUploadToServer.HasFile Then    
        Dim fileName As String = FileUploadToServer.PostedFile.FileName    
        Dim fileSize As Integer = FileUploadToServer.PostedFile.ContentLength    
        Dim fileExtension As String = Path.GetExtension(fileName).ToLower()    
        Dim extensionsAllowed As String() = {".pdf"}    
        If extensionsAllowed.Contains(fileExtension) Then    
            correctExtension = True    
        End If    
        If correctExtension Then    
            If fileExtension = ".pdf" Then    
                Try   
                    FileUploadToServer.PostedFile.SaveAs(filePath)    
                    SaveFileInfo(fileName, fileSize, FilePath)    
                    lblResult.Text = "File successfully uploaded and file path saved in database"
                    lblResult.ForeColor = Drawing.Color.Red    
                Catch ex As Exception    
                    lblResult.Text = "Unable to upload file"
                    lblResult.ForeColor = Drawing.Color.Red    
                End Try    
            End If
            ''Check if file already exists. If so, delete it and replace with new one
            If File.Exists(Server.MapPath(FilePath) & fileName) Then
                File.Delete(Server.MapPath(FilePath) & fileName)
            End If

            ' Get size of uploaded file, here restricting size of file
            fileSize = FileUploadToServer.PostedFile.ContentLength
            If FileSize <= 26214400 Then
                '1048576 byte = 1MB
                'Get file name of selected file
                fileName = Path.GetFileName(FileUploadToServer.FileName)
                'Save selected file into specified location
                FileUploadToServer.SaveAs(Server.MapPath(FilePath) & fileName)

                lblResult.Text = "File uploaded successfully!"
                lblResult.ForeColor = Drawing.Color.Red
                'blSucces = True
            Else
                lblResult.Text = "Attachment file size should not be greater then 250 MB"
                lblResult.ForeColor = Drawing.Color.Red
            End If
        Else    
            lblResult.Text = "File extension " + fileExtension + " is not allowed"
            lblResult.ForeColor = Drawing.Color.Red    
        End If
    End If

End Sub
Private Sub SaveFileInfo(ByVal strfilename As String, ByVal size As Integer, ByVal strPath As String)
    Using Sqlcon As New SqlConnection(connStr)
        Using cmd As New SqlCommand()
            Sqlcon.Open()
            cmd.Connection = Sqlcon
            cmd.CommandType = CommandType.StoredProcedure
            cmd.CommandText = "InsertOrUpdate"
            cmd.Parameters.Add(New SqlParameter("@EmpID", Session("EmpNum")))
            cmd.Parameters.Add(New SqlParameter("@ckRequestReview", ""))
            cmd.Parameters.Add(New SqlParameter("@RequestedTitle", txtTitleChange.Text))
            cmd.Parameters.Add(New SqlParameter("@TitleChangeComments", txtTitleComments.Text))
            cmd.Parameters.Add(New SqlParameter("@RequestedPay", txtPayGradeChange.Text))
            cmd.Parameters.Add(New SqlParameter("@PayChangeComments", txtPayComments.Text))
            cmd.Parameters.Add(New SqlParameter("@RequestedClass", txtClassSpecChange.Text))
            cmd.Parameters.Add(New SqlParameter("@ClassChangeComments", txtClassComments.Text))
            cmd.Parameters.Add(New SqlParameter("@EmpSignature", txtsign.Text))
            cmd.Parameters.Add(New SqlParameter("@finishedOrUnfinished", "Finished"))
            cmd.Parameters.Add(New SqlParameter("@ManagerID", divManager.SelectedValue))
            cmd.Parameters.Add(New SqlParameter("@DeptID", Session("DeptID")))
            cmd.Parameters.Add(New SqlParameter("@DirectorID", Session("DirectorNum")))
            cmd.Parameters.Add(New SqlParameter("@apFileName", SqlDbType.VarChar, 100))
            cmd.Parameters.Add(New SqlParameter("@apFilepath", SqlDbType.VarChar, 100))
            cmd.Parameters.Add(New SqlParameter("@FileSize", SqlDbType.Int))
            cmd.Parameters("@apFileName").Value = strfilename
            cmd.Parameters("@apFilepath").Value = strPath
            cmd.Parameters("@FileSize").Value = size
            cmd.ExecuteNonQuery()
            Dim rows As Integer = cmd.ExecuteNonQuery()
            If rows = 1 Then
                lblResult.Text = "Record Successfully Saved. Please log out and close your browser"
                lblResult.ForeColor = System.Drawing.Color.Red
            End If
        End Using
    End Using
End Sub

QuestionRe: Make uploading of file optional?? Pin
Richard MacCutchan13-Oct-15 9:59
mveRichard MacCutchan13-Oct-15 9:59 
AnswerRe: Make uploading of file optional?? Pin
samflex13-Oct-15 10:31
samflex13-Oct-15 10:31 
AnswerRe: Make uploading of file optional?? Pin
F-ES Sitecore13-Oct-15 23:28
professionalF-ES Sitecore13-Oct-15 23:28 
GeneralRe: Make uploading of file optional?? (SOLVED) Pin
samflex27-Oct-15 15:42
samflex27-Oct-15 15:42 
AnswerRe: Make uploading of file optional?? Pin
ZurdoDev15-Oct-15 2:14
professionalZurdoDev15-Oct-15 2:14 
QuestionEcommerce site development Pin
Member 1205587613-Oct-15 8:33
Member 1205587613-Oct-15 8:33 
SuggestionRe: Ecommerce site development Pin
Richard MacCutchan13-Oct-15 9:57
mveRichard MacCutchan13-Oct-15 9:57 
AnswerRe: Ecommerce site development Pin
F-ES Sitecore13-Oct-15 23:42
professionalF-ES Sitecore13-Oct-15 23:42 
QuestionRe: Ecommerce site development Pin
ZurdoDev15-Oct-15 2:15
professionalZurdoDev15-Oct-15 2:15 
QuestionHell All actually we want to make my website fast and i use repeater jquery ajax for get data using store procedure now we want to implement paging concept in this code but still remember our speed will not effect because we want ot fast website Pin
Member 1205134011-Oct-15 21:18
Member 1205134011-Oct-15 21:18 
QuestionRe: Hell All actually we want to make my website fast and i use repeater jquery ajax for get data using store procedure now we want to implement paging concept in this code but still remember our speed will not effect because we want ot fast website Pin
ZurdoDev13-Oct-15 2:23
professionalZurdoDev13-Oct-15 2:23 
Questionissue with accessing asp.net app over WAN Pin
Member 1191972211-Oct-15 20:27
Member 1191972211-Oct-15 20:27 
RantRe: issue with accessing asp.net app over WAN Pin
Richard Deeming12-Oct-15 1:45
mveRichard Deeming12-Oct-15 1:45 
GeneralRe: issue with accessing asp.net app over WAN Pin
Member 1191972212-Oct-15 18:37
Member 1191972212-Oct-15 18:37 
GeneralRe: issue with accessing asp.net app over WAN Pin
Richard Deeming13-Oct-15 1:40
mveRichard Deeming13-Oct-15 1:40 
GeneralRe: issue with accessing asp.net app over WAN Pin
Member 1191972213-Oct-15 18:29
Member 1191972213-Oct-15 18:29 
GeneralRe: issue with accessing asp.net app over WAN Pin
Richard Deeming14-Oct-15 1:57
mveRichard Deeming14-Oct-15 1:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.