Solved

AsyncFileUpload SaveAs Server.MapPath removing Slashes

Posted on 2010-09-21
3
1,366 Views
Last Modified: 2012-05-10
Using the AsyncFileUpload control and when setting the fullPath with Server.MapPath I get the following string 'C:Inetpubhostsemembercare.nethttpsdocsuserItemsUploadintreadwellRobert4.JPG'

The slashes were removed and the domain name is cut off.

Why are the slashes or characters being removed?
Protected Sub UploadedComplete_Click(ByVal sender As Object, ByVal e As AjaxControlToolkit.AsyncFileUploadEventArgs) Handles AFUMemberPicture.UploadedComplete



        Dim UserNameTB As TextBox = CType(CreateUserWizardStep2.ContentTemplateContainer.FindControl("UserName"), TextBox)

        Dim fileOK As Boolean = False



        Try

            If AFUMemberPicture.HasFile Then

                Dim fileExtension As String

                fileExtension = System.IO.Path. _

                GetExtension(AFUMemberPicture.FileName).ToLower()

                Dim allowedExtensions As String() = _

                {".jpg", ".jpeg", ".png", ".gif", ".bmp"}

                For i As Integer = 0 To allowedExtensions.Length - 1

                    If fileExtension = allowedExtensions(i) Then

                        fileOK = True

                    End If

                Next

                If fileOK Then

                    Try

                        Dim relativePath As String = "~/UserItems/Uploads/" + UserNameTB.Text + "/" + AFUMemberPicture.FileName

                        Dim fullPath As String = Server.MapPath(relativePath)

                        

                        'Save the file to user personal folder using fullPath.

                        AFUMemberPicture.SaveAs(fullPath)



                        'Retrieve the user ID in order to be used in Member Profile Picture Database call

                        Dim userID As Integer = getUserID(UserNameTB.Text)

                        'Insert or Update picture in table as relative Path

                        MemberProfilePicture(userID, relativePath)

                        'Update Picture image

                        Session("uploadedImageUrl") = relativePath

                        PreviewImage.ImageUrl = relativePath

                    Catch ex As Exception

                        UploadDetails.Text = "File could not be uploaded."

                    End Try

                Else

                    UploadDetails.Text = "Cannot accept files of this type."

                End If

            End If



        Catch ex As Exception

            ClientScript.RegisterStartupScript(Me.GetType(), "alert", "<script language='javascript'>alert('UploadedComplete_Click produce the following error: " + ex.Message + "');</script>")

            Response.Write(ex.Message)

        End Try

    End Sub

Open in new window

0
Comment
Question by:Robert Treadwell
3 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 33730763
Have you tried specifying @? its supposed to not escape so maybe it might have an effect. I am not sure but give it a try

I think its something like this

Dim fullPath As String = @Server.MapPath(relativePath)

or @ goes inside MapPath. Cant remember the exact syntax
0
 
LVL 7

Expert Comment

by:klakkas
ID: 33732340
I tried this:
        Dim relativePath As String = "~/UserItems/Uploads/1.gif"
        Dim fullPath As String = Server.MapPath(relativePath)

And got a correct response:
        ? fullpath
        "C:\temp\WebSite1\UserItems\Uploads\1.gif"

Can you please tell us the result of this line:
Dim relativePath As String = "~/UserItems/Uploads/" + UserNameTB.Text + "/" + AFUMemberPicture.FileName
                       
What is the exact contents of relativePath after this command?
0
 

Accepted Solution

by:
Robert Treadwell earned 0 total points
ID: 33789839
The Solution to my problem was that server did not have access to folder.  Once I assigned proper access to code and string concatenation work perfectly.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Windows 10 IIS and Windows Authentication to SQL 21 54
SQL Exceptions 3 39
Exit the loop 4 37
Need a starter for ETL protocol? 4 42
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

896 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now