Solved

How can I fetch docx or pdf file from MS SQL column for auto email attachment?

Posted on 2014-07-17
5
645 Views
Last Modified: 2014-08-05
Dear Experts,

I'm using ASPNETEmail and I'm looking how to automatically fetch docx or pdf file with specific filename from MS SQL database and attach to an email.

The best solution would be highly appreciated,


Thanks.
0
Comment
Question by:JimiJ13
  • 3
  • 2
5 Comments
 
LVL 41

Expert Comment

by:pcelba
ID: 40204928
This depends on the way how the file is stored on the MS SQL Server. Anyway it is easy - simply select the file by appropriate SQL command as any other value then save the retrieved value (yes, it can several megs but that's nothing for today's computers) to a temporary file and then attach this file to the e-mail message as any other file.

Finally you should delete the temp file.

Everything should be done at the ASP.NET server side.
0
 

Author Comment

by:JimiJ13
ID: 40206124
Hi pcelba,

Thanks for the affirmative idea.

The docx or pdf are stored tblName.DocImage (image) with filename in  tblName.DocFileName (varchar (50)) and PK at tblName.DocID (varchar(40)).

Can you give me a working code to retrieve the DocImage based on PK and save to a temp file?


Thanks.
0
 
LVL 41

Accepted Solution

by:
pcelba earned 500 total points
ID: 40206134
Let suppose you are using C#...

The most important part is the SQL Select command:
SELECT DocImage FROM tblName WHERE DocID = <YourPKvalue>

You just have to provide the correct PK value and implement the SQL command to C#.

To retrieve image data from SQL Server use following code:
http://www.codeproject.com/Articles/354639/Storing-and-Retrieving-Images-from-SQL-Server-Us
You just have to adapt it for e-mail attachment.

To save the retrieved image into a file you may also use following code:
http://www.global-webnet.net/blogengine/post/2008/09/23/Extension-Methods-(C-30)-FileToStr-and-StrToFile-extensions.aspx

And then simply attach the stored file into the e-mail.

You may also look at this code which use File stream data from SQL Server: http://www.c-sharpcorner.com/uploadfile/e628d9/inserting-retrieving-images-from-sql-server-database-without-using-stored-procedures/

And this code is similar to the first one: http://www.codeproject.com/Articles/10861/Storing-and-Retrieving-Images-from-SQL-Server-usin
0
 

Author Comment

by:JimiJ13
ID: 40210976
pcelba,

I will try it and let you know.

Thanks.
0
 

Author Closing Comment

by:JimiJ13
ID: 40241965
Great sources provided to help me come up with a solution.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MSP multi use software 4 111
Export Table to CSV - Access to CSV - using python 18 101
Java Loop 6 50
Where is Outlook in Paperport 14? 8 33
Skype is a P2P (Peer to Peer) instant messaging and VOIP (Voice over IP) service – as well as a whole lot more.
Computer science students often experience many of the same frustrations when going through their engineering courses. This article presents seven tips I found useful when completing a bachelors and masters degree in computing which I believe may he…
The viewer will learn how to successfully download and install the SARDU utility on Windows 8, without downloading adware.
XMind Plus helps organize all details/aspects of any project from large to small in an orderly and concise manner. If you are working on a complex project, use this micro tutorial to show you how to make a basic flow chart. The software is free when…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now