Get a Jumpstart with our Sample Apps
Results 1 to 2 of 2

Thread: Multiple embedded file Upload to MS SQL Server 2008 - Xbasic function needed

  1. #1
    Member
    Real Name
    Lawrence Sprowls
    Join Date
    Nov 2011
    Location
    USA
    Posts
    64

    Question Multiple embedded file Upload to MS SQL Server 2008 - Xbasic function needed

    Alpha Five v11 supports file upload using "linked file" and "embedded file" options. This video shows an Xbasic function that uploads multiple files using the "linked file" option:

    http://www.ajaxvideotutorials.com/V1...ined_Part3.swf

    Does anybody have an Xbasic function that uploads multiple files using the "embedded file" option?

    (Using MS SQL Server 2008 R2)

  2. #2
    Member
    Real Name
    Lawrence Sprowls
    Join Date
    Nov 2011
    Location
    USA
    Posts
    64

    Lightbulb Upload Multiple to MS SQL Server 2008 table (files are embedded, not linked)

    The Xbasic function FileUploadMultiple below is called by the Server-side event "After upload" in an Action Javascript: File Upload - User Defined Action. It uploads the files to an MS SQL Server table whose fields Filename, Filetype, and Filedata contain the names of the uploaded files, file extensions (e.g., .doc), and binary data. The Action Javascript is in a column button in a grid whose primary key is Applicant_ID. This grid has a linked grid that displays Filename and FileType. The two grids are linked by Applicant_ID.

    PHP Code:
    function FileUploadMultiple as (as p)
        
    ' upload files to SQL Server from File Upload - User Defined Action Javascript button'
        
        
    dim arr as p
        arr 
    e.filearray ' set array of files to upload'
        
        
    dim cn as sql::Connection
        dim cs 
    as c
        cs 
    e.tmpl.cs.connectionstring ' set connection string (Click Xbasic bottom tab of grid to verify)'
        
    cn.open(cs)
        
    dim sql as c
        sql 
    "insert into FileAttachment (Applicant_ID, Filename, Filetype, Filedata) values (:tApplicant_ID, :tFilename, :tFiletype, :tFiledata)"

        
    dim args as sql::Arguments
        args
    .Add("tApplicant_ID",convert_type(e.primaryKeyArray[1],"N")) ' Primary key for ALL files to be uploaded is Applicant_ID'
        
        
    dim count as n
        count 
    e.filecount
        dim i 
    as n
        
    for 1 to count ' loop through filearray'
            
    args.Add("tFilename",e.fileArray[i].fileName' set filename argument'
            
    args.Add("tFiletype",lastword(e.FileArray[i].fileName,".")) ' set filetype argument as characters following last period'
            
    dim data as b
            data 
    e.fileArray[i].data
            args
    .Add("tFiledata",data' set file data'
            
    dim flag as l
            flag 
    cn.Execute(sql,args' run sql'
        
    next i
        cn
    .Close() ' close connection'
        
        
    e.javascript "window.parent.{grid.object}.refreshLinkedContent();"
        ' refresh linked grid after uploading files'
    end function 

Similar Threads

  1. Xbasic function declaration - file upload
    By Cammy in forum Application Server Version 10 - Web/Browser Applications
    Replies: 8
    Last Post: 01-31-2011, 07:57 AM
  2. Slow access on SQL Server 2008
    By jbenton in forum Alpha Five Version 10 - Desktop Applications
    Replies: 0
    Last Post: 11-20-2010, 01:32 PM
  3. Win Server 2008 + SQL Server problem
    By jeffcogs in forum Application Server Version 10 - Web/Browser Applications
    Replies: 0
    Last Post: 07-30-2010, 10:51 AM
  4. SQL Server 2008 Views not available
    By steelman0948 in forum Alpha Five Version 10 - Desktop Applications
    Replies: 2
    Last Post: 07-05-2010, 02:20 PM
  5. SQL Server 2008 Express Question
    By cambriabiz in forum Application Server Version 10 - Web/Browser Applications
    Replies: 1
    Last Post: 02-22-2010, 06:58 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •