Archive

Archive for the ‘ASP.NET’ Category

FFMPEG with ASP.NET

March 29th, 2009 Arthur Gressick No comments

Ok, since my friend Art has been posting a lot of articles on FFMPEG recently I figured since I was working tonight with some FFMPEG that I would post a snippet or two with how to work with FFMPEG with .NET.

After you have saved the file down here is how to do the conversion

‘If the video is not already in flv format we need to do a conversion of it

If ext.ToString() <> “.flv” Then

Dim AppPath As String = Request.PhysicalApplicationPath

Dim inputPath As String = savePath

Dim outputPath As String = saveConvertedPath

Dim fileargs As String = ” -i “”" & inputPath & “”" “”" & outputPath & “”"”

Dim proc As New Diagnostics.Process()

proc.StartInfo.FileName = AppPath & “FFMPEGScout\ffmpeg.exe”

proc.StartInfo.Arguments = fileargs

proc.StartInfo.UseShellExecute = False

proc.StartInfo.CreateNoWindow = False

proc.StartInfo.RedirectStandardOutput = True

proc.Start()

proc.WaitForExit()

proc.Close()

End If

And here is how to snag the thumbnail

Dim AppPath As String = Request.PhysicalApplicationPath

Dim inputPath As String = savePath

Dim outputPath As String = saveConvertedPath

Dim fileargs As String = ” -i “”" & inputPath & “”" -s 108*80 -vframes 1 -f image2 -vcodec mjpeg “”" & outputPath & “”"”

Dim proc As New Diagnostics.Process()

proc.StartInfo.FileName = AppPath & “ffmpeg\ffmpeg.exe”

proc.StartInfo.Arguments = fileargs

proc.StartInfo.UseShellExecute = False

proc.StartInfo.CreateNoWindow = False

proc.StartInfo.RedirectStandardOutput = False

proc.Start()

Alright, we will post in more detail later but I just wanted to put some snippets out there before I hit the sack….

Getting ASP.NET Session Variables into Client Side Javascript

March 20th, 2009 Arthur Gressick No comments

Again, something simple is not always so simple. So we covered how do we get data from the database using Web Services and asynchronous callbacks but what if we needed to pass in like a User ID or something else that we are storing securely in the session?

We would need to pull down that session variable into our client side code so that we could send it back asynchronously in order to return the correct data set.

This is also handy for passing into Flash Vars.

Ok, so all that complicated mess for a one liner I know…

var UserID = ‘<%=Session(“UserID”)%>’;

I can then use that Javascript variable to pass it into an asynch web services call or use it as Flash vars etc.

Categories: ASP.NET, javascript Tags: ,

ASP.NET Sql Server Connection String

March 15th, 2009 Arthur Gressick No comments

In my recent post Asynchronous DataBinding with ASP.NET I eluded to the fact of connecting to Sql Server with .NET.  Since sometimes I have spent time looking for the simplest things when working on a project I figured I would take a moment and walk you through setting up Sql Server Connection strings in ASP.NET.

Step 1:  Define your connection string in your web.config file.

  1. Open web.config in your web project
  2. Locate the following section <appSettings/>
  3. REPLACE <appSettings/> with the following

<appSettings>

<add key=”connString” value=”server=YOURSERVER\YOURSQLSERVERINSTANCE;uid=SQLSERVERUSERID;pwd=SQLSERVERPASSWORD;database=DATABASENAME”/>

</appSettings>

Ok, so now you have a setting in your web.config file with the name of “connString” that you can access from anywhere in your application and if it changes you just change it one time and it is a global change.  You can also define multiple database connection strings here so you can reference multiple db’s.

Step 2: Reference the Connection String from your code behind file

  1. You need to import the System.Configuration.ConfigurationManager library, do that as follows

VB.NET

Imports System.Configuration.ConfigurationManager
Imports System.Data
Imports System.Data.SqlClient

C#.NET

using System.Configuration.ConfigurationManager;
using System.Data;
using System.Data.SqlClient;

Step 3: Establish as Sql Connection {so we are just going to declare a new SqlConnection that can be used by a DataAdapter, DataReader, etc.}

VB.NET

Dim con as New SqlConnection(AppSettings(“connString”))

C#.NET

SqlConnection con = new SqlConnection(AppSettings(“connString”));

Ok great, now we can use this Sql Connection throughout our application to interact with our sql server.

I will do another post that shows the advantages of connecting through TCP/IP instead of named pipes and the slight differences that we use in order to make that connection string work.