I'm trying to create a simple video gallery that pulls the videos from the recorded shows of a specific Ustream user with ASP.net. I've been doing some research and looking at the API Documentation but can't seem to figure it out all example are in PHP.
Can anyone help me on it..if possible then give me some Code or Blogs links for Asp.net with Ustream.
Thanks
Simply! Look here http://msdn.microsoft.com/en-us/library/ms525208(v=vs.90).aspx
You can use ADODB.Stream in Classic ASP (works in ASP.Net too)
Write this in asp:
'Set the content type to the specific type that you are sending.
Response.ContentType = "video/mp4"
Const adTypeBinary = 1
Dim strFilePath
strFilePath = server.mappath("stream.mp4")
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
Response.BinaryWrite objStream.Read
objStream.Close
Set objStream = Nothing
I think this will help you very much.
Related
I have found good information on how to automatically download a file to the client advertised as a solution of how to print using code
(https://forums.asp.net/t/1233841.aspx?How+do+I+print+from+Reporting+Services+AUTOMATICALLY+in+VB+Net+web+app+)
but what I need to do is have the code print the document without the user interacting.
From what I have found it appears this can not be done as one might casually think. ReportViewer for example does not have a 'print' method.
The only two solutions appears to be to use ProcessStart (which then means saving the file to the file system before printing which I dont want to do)
or maybe (will be researching this today) create a subscription using code and then delete it later.
You are not able to print a report directly from your asp.net page. The reason for this is security. If it allowed you to send a file through the network and onto the clients computer, and then search the computer for a printer, this could cause major security issues. The report viewer does have a print icon, but this disappears when you deploy the project and run the page remotely. I have faced the same issue in the past and found it best to just export the report to say PDF and allow the user to Download it. I have used the below code to accomplish this task in the past:
Private Sub CreatePDFMatrix(fileName As String)
' ReportViewer1.LocalReport.DataSources.Clear()
Dim adapter As New ReportDataSetTableAdapters.vwPrintTagsTableAdapter
Dim table As New ReportDataSet.vwPrintTagsDataTable
Dim month = MonthName(Date.Today.Month)
Dim year = Date.Today.Year
Dim p(1) As ReportParameter
Dim warnings() As Warning
Dim streamIds As String()
Dim mimeType As String = String.Empty
Dim encoding As String = String.Empty
Dim extension As String = String.Empty
Dim adpt2 As New ReportDataSetTableAdapters.vwPrintTagsTableAdapter
adapter.FillForMainReport(table, DropDownList1.SelectedValue, g_Company, g_Division)
Me.ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("DataSet1", CType(table, DataTable))) 'Add(New ReportDataSource("ReportingData", CType(table, DataTable)))
Me.ReportViewer1.DataBind()
Dim viewer = ReportViewer1
viewer.ProcessingMode = ProcessingMode.Local
viewer.LocalReport.ReportPath = "Report1.rdlc"
p(0) = New ReportParameter("MonthYear", month & "-" & year)
Dim check = DropDownList1.SelectedValue
ReportViewer1.LocalReport.SetParameters(p(0))
p(1) = New ReportParameter("Location", DropDownList1.SelectedValue)
ReportViewer1.LocalReport.SetParameters(p(1))
Try
Dim bytes As Byte() = viewer.LocalReport.Render("PDF", Nothing, mimeType, encoding, ".pdf", streamIds, warnings)
Response.Buffer = True
Response.Clear()
Response.ContentType = mimeType
Response.AddHeader("content-disposition", Convert.ToString((Convert.ToString("attachment; filename=") & fileName) + ".") & extension)
Response.BinaryWrite(bytes)
' create the file
Response.Flush()
Catch ex As Exception
Debug.Print(ex.ToString)
End Try
End Sub
I created a protected area in my website, where only registered users can logon to download a restricted application (exe). But they can copy the download link and make it available on internet, so I am trying to find the simplest way to hide the download link (using ASP classic, if possible).
Here is what I got so far: http://forums.aspfree.com/code-bank-54/download-manager-downloading-files-secure-location-classic-asp-65239.html. But when using this download manager, the exe application unexplainably looses its digital signing :(
Please, can anyone give me some ideas? Maybe using PHP or Flash?
Thanks!
Here is the solution I found, using ASP classic:
<%
Option Explicit
Response.Buffer = True
If (not Session("Logged")) Then Response.End
Dim objFso
Dim objStream
Dim strFileName
Dim strFilePath
strFileName = "App.exe"
strFilePath = "d:\yoursitefolder\protectedfolder\"
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
If objFso.FileExists(strFilePath & strFileName) Then
Response.AddHeader "Content-disposition", "filename=" & strFileName
Response.ContentType = "application/octet-stream"
Response.AddHeader "Pragma", "no-cache"
Response.AddHeader "Expires", "0"
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Type = 1
objStream.Open
objStream.LoadFromFile strFilePath & strFileName
Response.BinaryWrite(objStream.Read())
objStream.Close
Set objStream = Nothing
End If
Set objFso = Nothing
%>
I have a Classic ASP application which allows users to download excel documents provided by a 3rd party vendor. Below is sample code. If the document size is greater than 4mb, I get an error "Response buffer limit exceeded".
I did some research and tried different things. Only increasing the buffer limit in IIS resolved my issue. But my systems team is reluctant to make this change on production.
Is there an alternate solution? Is there a solution available in ASP.Net?
set objDoc = Server.createobject("Some.Object")
objDoc.DocId doc_id
bin_obj = objDoc.Binary
set objDoc = Nothing
Response.buffer = TRUE
Response.ContentType = "application/msexcel"
Response.AddHeader "Cache-Control", "public"
Response.AddHeader "Pragma", "public"
Response.AddHeader "Content-Disposition", "attachment;filename=test.xls"
Response.BinaryWrite bin_obj
Response.Flush
Response.End
You need push content part by part, ex. by 1Mb per block. If your COM object ("Some.Object") dosn't allow read by block, you can make it using ADODB.Stream object with method stream.Read(count).
UPDATE:
Option Explicit
Dim streamS, streamB
Set streamS = Server.CreateObject("ADODB.Stream")
streamS.Type = 1 'Binary stream
streamS.Open
streamS.LoadFromFile Server.MapPath("/Nissan_Qashqai_IDTR.rar")
Set streamB = Server.CreateObject("ADODB.Stream")
streamB.Type = 1
streamB.Open
Dim blockSize
blockSize = 1024 ' block size is 1 KB
Response.AddHeader "Content-Disposition", "attachment;filename=MyTestBinryFile.bin"
Response.AddHeader "Content-Length", streamS.Size
Response.ContentType = "application/octet-stream"
Dim i
For i = 0 To streamS.Size - 1 Step blockSize
streamB.Position = 0
streamS.CopyTo streamB, blockSize
streamB.Position = 0
Response.BinaryWrite(streamB.Read)
Response.Flush
Next
streamS.Close
Set streamS = Nothing
streamB.Close
Set streamB = Nothing
Response.Flush
I work in a very large, complex Intranet environment. I have run into a very unique issue that I cannot seem to resolve.
Forwarning
The technologies I mention are very outdated and that is the way is has to stay. I work in a very large enterprise and they have a ton of legacy things in place. I normally work on the modern side of things, but this got placed in my lap.
The problem:
We have a file located on our IIS 7.x server with path \serverName\shareName\wwwroot\myfile.jpg. I need to copy this file to a webDav location of a DIFFERENT web server using ASP , vbscript, or another similar web technology. For a multitude of security implications, I don't have access to the webDav UNC path, only the http: path. I am able to map this drive and access the http: location using windows explorer. I can even manually copy files, create files, and delete them. However, when I try to use a script, I get no where.
I am not great with vbscript so bare with my attempts:
Attempt 1:
Set oShell = CreateObject("WScript.Shell")
strCommand = oShell.Run("Xcopy ""sourceLocation"" ""destination location"" /S /Y", 0, True)
If strCommand <> 0 Then
MsgBox "File Copy Error: " & strCommand
Else
MsgBox "Done"
End If
Attempt 2:
<%
dim objFSOpublish
set objFSOpublish = CreateObject("Scripting.FileSystemObject")
strCurrentUNCfull = "sourcePath"
mPublishPath = "destinationPath"
objFSOpublish.CopyFile strCurrentUNCfull, mPublishPath
set objFSOpublish = nothing
%>
I have no idea if this is even possible to do without the webDav UNC path because I don't have much experience with webDav. If it is possible I have exhausted my limited knowledge in this space and need help badly. I scoured Google tirelessly trying to find a similar issue to no avail. Any and all help or direction will be greatly appreciated.
You're going to want to do something like this:
On Error Resume Next
sUrl = "YourURLHere"
sFile = "UNCPathToYourFile"
'Here we are just reading your file into an ODB
'stream so we can manipulate it
Set oStream = CreateObject("ADODB.Stream")
oStream.Mode = 3
oStream.Type = 1
oStream.Open
oStream.LoadFromFile(sFile)
'Here we are doing the upload of the oStream
'object we just created.
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.Open "POST", sUrl, False
oHTTP.SetRequestHeader "Content-Length", oStream.Size
oHTTP.Send oStream.Read(oStream.Size)
'Check for errors.
If Err = 0 Then
Wscript.Echo oHTTP.responseText
Else
Wscript.Echo "Upload Error!" & vbCrLf & Err.Description
End If
'Optionally close out our objects
oStream.Close
Set oStream = Nothing
Set oHTTP = Nothing
Here is the code I am currently using with the actual file path redacted. Let me know if you see anything that is incorrect.
The page is saved as a .ASP.
<%
sUrl = "http://server.site.com:80/subDomain/wwwroot/"
sFile = "\\server\developmentShare\wwwroot\page.htm"
'Here we are just reading your file into an ODB
'stream so we can manipulate it
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Mode = 3
oStream.Type = 1
oStream.Open
oStream.LoadFromFile(sFile)
'Here we are doing the upload of the oStream
'object we just created.
Set oHTTP = CreateObject("MSXML2.ServerXMLHTTP")
oHTTP.Open "POST", sUrl, False
oHTTP.SetRequestHeader "Content-Length", oStream.Size
oHTTP.Send oStream.Read(oStream.Size)
'Check for errors.
If Err = 0 Then
Wscript.Echo oHTTP.responseText
Else
Wscript.Echo "Upload Error!" & vbCrLf & Err.Description
End If
'Optionally close out our objects
oStream.Close
Set oStream = Nothing
Set oHTTP = Nothing
%>
Okay, I've seen this asked in a couple of spots but never really got an answer that helped or that I understood. I'm just starting back on ASP.net and am using VS 2010 on the 4.0 framework.
I found some code online to allow you to generate an .xls Excel file from a dataset.
The code is below, but when I run this code from a button outside of my ajax update panel it works perfectly. If I execute the code from a button inside the update panel (where I need it to be) then I get the following:
Sys.WebForms.PageRequestManagerParserErrorException The message received from the server could not be parsed.
I have tried the two versions of the header shown and have tried the completerequest() instead of response.end.
Could someone explain to me why this doesn't work in the update panel and how I could make it work in the update panel?
Thanks in advance!
Protected Sub ExportDataSetToExcel(ByVal ds As DataSet, ByVal filename As String)
Dim response As HttpResponse = HttpContext.Current.Response
' first let's clean up the response.object
response.Clear()
response.Charset = ""
' set the response mime type for excel
response.ContentType = "application/vnd.ms-excel"
'response.ContentType = "application/octet-stream"
response.AddHeader("Content-Disposition", "attachment;filename=""" & filename & """")
' create a string writer
Using sw As New StringWriter()
Using htw As New HtmlTextWriter(sw)
' instantiate a datagrid
Dim dg As New DataGrid()
dg.DataSource = ds.Tables(0)
dg.DataBind()
dg.RenderControl(htw)
response.Write(sw.ToString())
'HttpContext.Current.ApplicationInstance.CompleteRequest()
response.End()
End Using
End Using
End Sub
Try this:
response.Flush();
HttpContext.Current.ApplicationInstance.CompleteRequest()
Do not call reposne.End()
check out this sample:
How to download/open the file that I retrive by server path?
it shows how to write a handler to DL a file.
Sorry, I know is a bit late, but found the answer right now.
Try with this answer. I resolve it doing what it is said here and it works perfectly