예제 #1
0
        private void SaveHash()
        {
            SqlConnection connection = new SqlConnection(_provider.ConnectionString);
            SqlCommand    command    = connection.CreateCommand();

            if (_provider.StoreHashProcedure != null && _provider.StoreHashProcedure.Length > 0)
            {
                command.CommandType = System.Data.CommandType.StoredProcedure;
                command.CommandText = _provider.StoreHashProcedure;
            }
            else
            {
                command.CommandText = string.Format("UPDATE [{0}] Set [{1}]=@Hash Where $IDENTITY=@Identity", _provider.TableName, _provider.HashColumnName);
            }
            SqlServerBlobStream.AddWithValue(command.Parameters, "@Hash", ToHex(Hash));
            SqlServerBlobStream.AddWithValue(command.Parameters, "@Identity", _blobStream.Identity);

            connection.Open();
            try { command.ExecuteNonQuery(); }
            finally { connection.Close(); }
        }
예제 #2
0
        public override Stream CreateStream()
        {
            // _blobStream = new SqlServerBlobStream(this);
            // Use the BIG constructor that takes in _everything_ and figures out how to use it
            _blobStream = new SqlServerBlobStream(_provider.ConnectionString, _provider.TableName, _provider.DataColumnName, _provider.PartialFlagColumnName, _provider.FileNameColumnName, this.FileName, _provider.MIMETypeColumnName, this.ContentType,
                _provider.CreateProcedure, _provider.OpenProcedure, _provider.WriteProcedure, _provider.ReadProcedure, _provider.CleanupProcedure, _provider.RenameProcedure, _provider.StoreHashProcedure, _provider.DeleteProcedure);

            _identity = _blobStream.Identity;   //Get generated identity (if any) from the stream

            // If hash algorithm is specified, enlcose the blobstream in a hash crypto-transformation
            if (_hashAlgorithm != null)
                return new CryptoStream(_blobStream, _hashAlgorithm, CryptoStreamMode.Write);

            return _blobStream;
        }
예제 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //Make sure there is an 'id' in the query string
            if (Request.QueryString["id"] == null) throw new ArgumentException("No file id was specified");

            //Make sure there is no crap in the HTTP headers that would be sent
            Response.ClearHeaders();
            Response.BufferOutput = false;

            //Get ID of file to load form the database
            int id = int.Parse(Request.QueryString["id"]);

            SqlServerUploadStorageProvider provider = (SqlServerUploadStorageProvider)UploadStorage.Provider;

            // Use the provider attributes to connect to the database and use stored procs or generated sql
            // to get a stream on the file.
            SqlServerBlobStream blob = null;
            if (provider.OpenProcedure != null && provider.ReadProcedure != null)
            {
                blob = new SqlServerBlobStream(
                    provider.ConnectionString, id, provider.OpenProcedure, provider.ReadProcedure, FileAccess.Read);
            }
            else
            {
                blob = new SqlServerBlobStream(
                    provider.ConnectionString, provider.TableName, provider.DataColumnName, id,
                    provider.FileNameColumnName, provider.MIMETypeColumnName, FileAccess.Read);
            }

            // Set the filename and MIME-type of the response to that given by the file
            Response.ContentType = blob.MIMEType;
            Response.AddHeader("Content-disposition", "attachment;filename=\""+blob.FileName+"\"");

            //Pipe the file data to the browser
            DataPipe.Pipe(blob, Response.OutputStream);

            // Close the stream from the DB.
            blob.Close();

            //Finished!
            Response.End();
        }