.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
Easy Web
Imran Ghani
Post New Web Links

How to store and retrieve file(.txt,.doc,.jpg,n etc) into and from sql db?

Posted By:      Posted Date: October 21, 2010    Points: 0   Category :ASP.Net
 

Can anybody help me solve my problem?


Below is the coding that I used to store without problem but when come to retrieve no display..


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim len As Integer = Upload.PostedFile.ContentLength.ToString
        Dim file As Byte() = New Byte(len - 1) {}
        Upload.PostedFile.InputStream.Read(file, 0, len)
        ' Insert the file and comment into the database
        Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
        Try
            connection.Open()
            Dim cmd As New SqlCommand("insert into Text(filecontent,comment) values (@filecontent,@comment)", connection)
            Dim prmPersonImage As New SqlParameter("@filecontent", SqlDbType.Binary)
  &


View Complete Post


More Related Resource Links

How to store and retrieve multiple values in a single session variable .

  

I want to store employee name,designation and department in session variable and
retrieve in another page how to do this.


retrieve large file from database ?

  

I have a database table that works as a file repository.  Currently there are binaries stored in there and I want to pull the "large" ones out in chunks.  Some of these files are in excess of 500 MB.  I have business rules that dictate if the file is >5MB to transmit in chunks.  <5MB and I can load into memory and rip out.  I got the uploading in chunks to work, but how do I get it to pull it out of the DB in chunks?

Right now I'm getting hit with a 'System.OutOfMemory' exception.  But when I recreate the byte array of the SAME size (empty though) it doesn't break.

Download Chunks (DAL)

public byte[] getBytesByDataID(int chunkSize, string dataID)
        {
            string query = "SELECT data.data " +
                " FROM data " +

How to retrieve the mysql backup file (backup.sql) into sql

  
--SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";

--
-- Database: `ebhcemr`
--
CREATE DATABASE ebhcemr DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
USE ebhcemr;
go
-- --------------------------------------------------------

--
-- Table structure for table `addresses`
--

CREATE TABLE  addresses (
  id int(11) NOT NULL default '0',
  line1 varchar(255) default NULL,
  line2 varchar(255) default NULL,
  city varchar(255) default NULL,
  [state] varchar(35) default NULL,
  zip varchar(10) default NULL,
  plus_four varchar(4) default NULL,
  country varchar(255) default NULL,
  foreign_id int(11) default NULL,
  PRIMARY KEY  (id),
  KEY foreign_id (foreign_id)
)ENGINE=MyISAM DEFAULT CHARSET=latin1;


Open a Batch File in Sql Store Procedure

  

Hi


I have to open a batch file automatically in sql. So i have used the below command.

EXECUTE master.dbo.xp_cmdshell 'D:\Databases\batch\123.bat'

Its worked for few times. After that its not working.

One time i have stopped before the process is complete.May be this is the issue.

Now its returns null value.


Can anyone help me how can i open the file in sql.


Thanks & Regards,

Visa.G


Use Attachment Control to store URL to file and not the file

  
I want to use the Attachment to a custom list, but I don't want to store the file I want to store the URL to the file.  I can use the Link column, but what I want the browse funtionality and I dont get that with the link column.

SharePoint Custom List Attachment to Store URL and Not a File

  

I need to ust the attachment column for a list, but I want to store the URL NOT the attached file.  I could use a Link Column type, but doesn't have the browse utility that the attachement column has. 

Any ideas?  I would like to store the URL and not the FILE with the browse utility


How to retrieve the original XAML file name from code

  

Hi,

I would like to display the original filename for the element the mouse is hovering over. Can I retrieve the original XAML-FileName from a FrameworkElement in code?

Regards,
Paul Sinnema


Take a look at my blog: http://paul.sinnema.ch

Where to store file locations in 3-Tier Architecture Website?

  

In my website I have reference to some file locations as follows:-
string Path = Server.MapPath(".\\HelpFiles\\FileDirectory\\");
        string Path1 = Server.MapPath(".\\HelpFiles\\FileDirectory\\File1.xml");
        string Path2 = Server.MapPath(".\\HelpFiles\\FileDirectory\\File2.xml");       
        string Path3 = Server.MapPath(".\\HelpFiles\\FileDirectory\\File3.xls");
At present I have stored these locations in the Defau

How can use A resource file to Store Page name constants

  

How can i use the .net Default folder App_GlobalResources Folder to store a Resource file which contains all the Page names?

Currently i added a a Resource file (PageNameConstants.resx) and set the name filed and Value field but i cannot access any of those by calling

App_GlobalResources.PageNameConstants.HOME(HOME has the value ~/Home.aspx)

Please help



Store file into database

  

Below is the code I use to store file into database but there are a few problems.

1. couldn't store file larger than 4mb

2. couldn't store doc,docx,xlsx but only .txt


my table column are:

id - int

file_data - varbinary(max)

name - varchar(max)

content_type - varchar(50)

file_size - int


can anybody help me in solving this?thx


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Upload.HasFile AndAlso Upload.PostedFile IsNot Nothing Then
            Dim ilength As Integer = Convert.ToInt32(Upload.PostedFile.InputStream.Length)
            Dim content As String = Upload.PostedFile.ContentType
            Dim file_name As String = Upload.PostedFile.FileName.Trim()
            Dim bytecontent As [Byte]() = New [Byte](ilength - 1) {}

            Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirector

Store file into database

  

the following are the code I used to store file into database but it doesnt work.

so pls somebody help me in this problem.

thx


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim connection As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True")
        ' Read the file and convert it to Byte Array
        Dim filePath As String = FileUpload1.PostedFile.FileName.ToString
        Dim filename As String = Path.GetFileName(filePath)
        Dim fs As FileStream = New FileStream(filePath, FileMode.Open, FileAccess.Read)
        Dim br As BinaryReader = New BinaryReader(fs)
        Dim bytes As Byte() = br.ReadBytes(Convert.ToInt32(fs.Length))
        br.Close()
        fs.Close()

        'insert the file into database
        Dim strQuery As Str

retrieve NTFS file / folder permissions

  

Using .NET 4.0, is there a good way to retrieve the NTFS permissions for a given file or folder?   Specifically, I would like to know if the current Windows user has write / delete permissions for a given folder.   I don't want to modify the permissions, just want to look at them to know if its safe to continue running.

 

 

 

 


How to store binary (file) in SQL server using Entity Framework?

  

Hi,

 

Sorry for the newbie question. I want to store files in SQL server. I searche a lot but didn't found what I could use. I'd like to use Entity Framework and C# in Visual Studio 2010. Could somebody help me with a code snippet or pointing me to a good howTo where I could find and understand how to store files in SQL using Entity Framework 4 and C#?

 

Thanks,

G


I'm not a development! I'm an infrastructure engineer! Please be patient on the development forums! :)

How to store binary (file) in SQL server using Entity Framework?

  

Hi,

 

Sorry for the newbie question. I want to store files in SQL server. I searche a lot but didn't found what I could use. I'd like to use Entity Framework and C# in Visual Studio 2010. Could somebody help me with a code snippet or pointing me to a good howTo where I could find and understand how to store files in SQL using Entity Framework 4 and C#?

 

Thanks,

G


I'm not a development! I'm an infrastructure engineer! Please be patient on the development forums! :)

How to store the result of a query in a CSV file

  

Hello,

I'd like to create a stored procedure that runs a query and stores the resulting data in a CSV file.

How may I achieve this ?

Thanks


Same file name, different folders. Store in document library separately

  

When I set up a document library in SharePoint 2007 (with versioning), I want to upload files with the same file name, but in different folders. I want each of the the files to have it's own version history. The files must remain distinct, as they are entirely different files with their own context in a folder hierarch.

Can I do this? How?

You can probably tell I am brand new to using SharePoint.

Thanks,


Jon Jacobs This message was composed entirely from recycled electrons.

Groove and Sharepoint Workspace 2010 - error during binary file store initiatlization.

  

I had groove and now have sharepoint workspace.   I had groove get hung up for a couple of hours and finally shut down my computer.   I got a "error occured during binary file store initialization" message.   I tried deleting and clean up all of the groove files but no luck.   I now have Sharepoint Workspace.  The message I get is "SharePoint Workspace is unable to continue because an error occurred during binary file store initialization."   Any coaching is appreciated. 


Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend