Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Better soluton: ADVICE
 
1) Insert pdf in sql database and read 
or
2) Insert location in sql and read from file
 
I have many pdf files using azure

Misrosoft sql server 2017
 
Thanks


What I have tried:

Advice

I have many pdf files using azure

Misrosoft sql server 2017
Posted
Updated 28-Jul-18 2:38am

Depends on what you are doing with it, and why.

There is no "better solution" - some will be better under these circumstances, others will be better under those. No one solution will fit all circumstances.

Storing PDF's directly into your DB has some advantages, but also can increase bandwidth usage, and that can potentially slow SQL down, as well as perhaps making the SQL database file significantly larger with all the backup drawbacks that implies - but storing the location means that every system which wants to retrieve the data needs access to that common location, and also that you need to take care of potential filename conflicts: there could be hundreds of documents called "Report" for example.

Think about what exactly you are trying to achieve, and how the documents are to be handled in your system as a whole - then you can make rational decisions on how to store things.
 
Share this answer
 
v2
Comments
Goran Bibic 28-Jul-18 8:56am    
Insert file locattion in sql

querySaveStaff.Parameters.Add("@file_location", SqlDbType.VarChar, 255).Value = file_locationTextBox.Text;

How to retrieve file from some location?

I try on datagrid selection changes but not succesfull



//byte[] bt;

try
{
if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)
{
//byte[] ap = (byte[])documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value;
//MemoryStream ms = new MemoryStream(ap);
////dataPictureBox.Image = System.Drawing.Image.FromStream(ms);

//axAcroPDF1.src = LocalEncoding.GetString(ms.ToArray());








//using (OpenFileDialog ofd = new OpenFileDialog()
//{
// ValidateNames = true, Multiselect = false, Filter = "PDF|*.pdf" }) {
// if (ofd.ShowDialog() == DialogResult.OK)
// {
// bt = null;
//MemoryStream fs = new MemoryStream(bt);
//bt = new byte[fs.Length];
// fs.Read(bt, 0, (id)fs.Length);
// axAcroPDF1.src = LocalEncoding.GetString(fs.ToArray());
//fs.Close();
// }
// }


StringBuilder text = new StringBuilder();
// using (PdfReader reader = new PdfReader("D:\\SPEDICIJA MERIDIJAN\\informacija\\SKM_28718052812170.pdf"))
using (PdfReader reader = new PdfReader("D:\\SPEDICIJA MERIDIJAN\\informacija\\SKM_28718052812170.pdf"))
{
for (int i = 1; i <= reader.NumberOfPages; i++)
{
text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
}
}
// You can read from text.ToString();










//byte[] ap = (byte[])documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value;
//string tempName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".pdf");
//File.WriteAllBytes(tempName, ap);
//axAcroPDF1.src = tempName;

}
else {
axAcroPDF1.src = null;
}
}
catch
{
axAcroPDF1.src = null;
}
Goran Bibic 28-Jul-18 8:56am    
Some help?
Goran Bibic 28-Jul-18 8:58am    
Some solution like read from String path(file_locationTextBox.Text)
If you have a webserver or cloud storage you could store your pdf files there, then in your SQL Server database you could store only the URL's to the pdf files.
Don't try to do this with Dropbox, it is no longer possible to share URL's in a simple way.
If your files are not too large you could retrieve them like this:
using(WebClient client = new WebClient()) {
   string s = client.DownloadString(url);
}
 
Share this answer
 
v2
Comments
Goran Bibic 28-Jul-18 8:53am    
Google cloud 100 gb? Maybe that solution?
RickZeeland 28-Jul-18 9:00am    
That should work, go to Google Drive and click 'get shareable link'.
It will look something like this: https://drive.google.com/open?id=0B5ZQZ7etv3XpaEZpYlBXcUlOXYZ
Goran Bibic 28-Jul-18 8:56am    
Insert file locattion in sql

querySaveStaff.Parameters.Add("@file_location", SqlDbType.VarChar, 255).Value = file_locationTextBox.Text;

How to retrieve file from some location?

I try on datagrid selection changes but not succesfull



//byte[] bt;

try
{
if (documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value != null)
{
//byte[] ap = (byte[])documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value;
//MemoryStream ms = new MemoryStream(ap);
////dataPictureBox.Image = System.Drawing.Image.FromStream(ms);

//axAcroPDF1.src = LocalEncoding.GetString(ms.ToArray());








//using (OpenFileDialog ofd = new OpenFileDialog()
//{
// ValidateNames = true, Multiselect = false, Filter = "PDF|*.pdf" }) {
// if (ofd.ShowDialog() == DialogResult.OK)
// {
// bt = null;
//MemoryStream fs = new MemoryStream(bt);
//bt = new byte[fs.Length];
// fs.Read(bt, 0, (id)fs.Length);
// axAcroPDF1.src = LocalEncoding.GetString(fs.ToArray());
//fs.Close();
// }
// }


StringBuilder text = new StringBuilder();
// using (PdfReader reader = new PdfReader("D:\\SPEDICIJA MERIDIJAN\\informacija\\SKM_28718052812170.pdf"))
using (PdfReader reader = new PdfReader("D:\\SPEDICIJA MERIDIJAN\\informacija\\SKM_28718052812170.pdf"))
{
for (int i = 1; i <= reader.NumberOfPages; i++)
{
text.Append(PdfTextExtractor.GetTextFromPage(reader, i));
}
}
// You can read from text.ToString();










//byte[] ap = (byte[])documentsDataGridView.SelectedRows[0].Cells["pdf_file"].Value;
//string tempName = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName() + ".pdf");
//File.WriteAllBytes(tempName, ap);
//axAcroPDF1.src = tempName;

}
else {
axAcroPDF1.src = null;
}
}
catch
{
axAcroPDF1.src = null;
}
Goran Bibic 28-Jul-18 8:56am    
Some help?
Goran Bibic 28-Jul-18 8:58am    
Some solution like read from String path(file_locationTextBox.Text)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900