SNB Solutions - Baja California Software Company
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
File upload control in ASP.NET 2.0
stoian_bycovich
#1 Posted : Friday, February 26, 2010 2:17:17 PM

Rank: Administration

Medals:

Groups: Administrators
Joined: 1/2/2010
Posts: 79
Points: 10,237
Location: Cabo San Lucas

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Recent days I got a project with requirement to play flv video, so I found an free for non commecrial purposes flv player, but the problem that I had was how to find way to "control" what the player is going to play by the users' choise. So what I needed was to "inject" this javascript embedded player dynamically into pages' html, that way I got the power to control what is going to be passed to and played by the player (I've used url query string to pass videos' file name to the player as parameter). So here how I did it:

What I did in aspx file was to put holder for the javascript player code:

<asp:PlaceHolder ID="PlaceHolder1" runat="server" />

Then I used HtmlGenericControl to "inject" the javascript player code into holder:

Dim Span As New HtmlControls.HtmlGenericControl("span")

Span.Attributes.Add("style", "z-index: 80")
Span.InnerHtml = "<a id=""container"" href=""http://www.macromedia.com/go/getflashplayer""></a>" & _
"<script type=""text/javascript"" src=""swfobject.js""></script>" & _
"<script type=""text/javascript"">" & _
"var s = new SWFObject(""mediaplayer.swf"",""mediaplayer"",""" & "400" & """,""" & "300" & """,""" & "8" & """);" & _
"s.addParam(""allowfullscreen"",""true"");" & _
"s.addVariable(""width"",""" & "400" & """);" & _
"s.addVariable(""height"",""" & "300" & """);" & _
"s.addVariable(""file"",""" & "" & Request.QueryString("filename") & ".flv" & """);" & _
"s.addVariable(""image"",""" & "" & """);" & _
"s.addParam(""wmode"", ""transparent"");" & _
"s.write(""container"");" & _
"</script>"

PlaceHolder1.Controls.Add(Span)
Best regards,
Stoyan Bukovich
Executive manager
SNB Solutions

Cell.: +52 6241 616969
E-mail: s.bucovich@snb-bg.com
Web: www.snb-bg.com
Sponsor  
 
Eannouncements.net SNB Solutions Eanuncios.net

Eannouncements.net the place for your announcement.

SNB Solutions - Software and computing services company.

Eanuncios.net el lugar para su anuncio.

stoian_bycovich
#2 Posted : Friday, February 26, 2010 2:17:46 PM

Rank: Administration

Medals:

Groups: Administrators
Joined: 1/2/2010
Posts: 79
Points: 10,237
Location: Cabo San Lucas

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Do you want to send an e-mail message with your asp.net form? Ok, here is sample code.

First let's import the necessery namespace:

Imports System.Net.Mail

Second let's write handlers' code for button click event (exp.: button send click):

If Page.IsValid() Then

Dim mySmtpClient As New SmtpClient
Dim myMail As New MailMessage
Dim myFrom As New MailAddress("test@test.com")
Dim myTo As New MailAddress("someone@test.com")

myMail.BodyEncoding = System.Text.Encoding.UTF8
myMail.To.Add(myTo)
myMail.From = myFrom
myMail.Subject = "Web mail"
myMail.Body = vbCrLf & vbCrLf & "Hi, my name is John Anderson. I'am interested in ..."
mySmtpClient.Host = "test.com"
mySmtpClient.Credentials = New System.Net.NetworkCredential("webmaster@test.com", "password123", "test.com")

Try
mySmtpClient.Send(myMail)
lblAlert.Text = "Mail sending success message"
Catch ex As Exception
lblAlert.Text = "Mail sending fail"
End Try

End If
Best regards,
Stoyan Bukovich
Executive manager
SNB Solutions

Cell.: +52 6241 616969
E-mail: s.bucovich@snb-bg.com
Web: www.snb-bg.com
stoian_bycovich
#3 Posted : Friday, February 26, 2010 2:53:49 PM

Rank: Administration

Medals:

Groups: Administrators
Joined: 1/2/2010
Posts: 79
Points: 10,237
Location: Cabo San Lucas

Thanks: 0 times
Was thanked: 0 time(s) in 0 post(s)
Ok, I was sitting infront of the computer screen and was thinking what to write so i decide to give you a clue how to use file upload control. Enough talking time for coding :)

- In our aspx file

<asp:FileUpload ID="FileUpload1" runat="server />

<asp:Button ID="Button1" runat="server Text="Upload File" />

- In our code behind aspx.vb file (by the way I am using VB)

Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

FileUpload1.SaveAs("C:\") ' if you point to a server path don't forget to set write permission for internet guest account

End Sub

So thats it if you have future questions please ask

Best regards,
Stoyan Bukovich
Executive manager
SNB Solutions

Cell.: +52 6241 616969
E-mail: s.bucovich@snb-bg.com
Web: www.snb-bg.com
Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.