I have to take an image from my system and save it in the form of bytes to a folder in the server.Than i have to give the path of the .txt file i.e the converted image file to the database by creating a table in it.Finally i want to retrieve it from the database.It should be a windows application.Is this possible?
Yes it is possible...
You are just storing the path of the image file that you created.
The path is just going to be a simple string.
While retrieving, you need to take the path from the database and set it as the image source path to the ImageBox in the windows application.
Example:
for selecting the image file.
string DestinationPath = "D:\\test.jpg";
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
byte[] bt = File.ReadAllBytes(ofd.FileName);
File.WriteAllBytes(DestinationPath, bt);
}
//Store DestinationPath into the database.
for retrieving and displaying in a PictureBox
string pathFromDatabase = "D:\\test.jpg"; //Retrieve from database
pboxDisplay.Image = Image.FromFile(pathFromDatabase); //Assuming pboxDisplay as the PictureBox control
hope it helps...
try this
from data base
byte bt = File.ReadAllBytes("C:\\test.jpg");
File.WriteAllBytes("C:\\test1.jpg",bt)
" bt " you can upload this byte to Database while retrieving bytes from data base use File.WriteAllbytes ...
Related
I have an apps script that generates a 2D array. I would like to export this array to a folder on my Google Drive in legacy .XLS format, ideally without first creating a Google Sheet and then converting that sheet.
I thought I could turn my array into a CSV string and convert that to blob with the appropriate MimeType, and save that in Drive.
However, when I download the file from Drive and open it, the values aren't separated (tried "," and ";" as delimiter).
My script below, with a simplified array for example.
function createXls() {
var data = [["a","b","c"],["d","e","f"]];
var csvString = toCsv(data);
var xlsName = "here goes the filename";
var driveFolder = DriveApp.getFolderById("hereGoesTheFolderId");
var blob = Utilities.newBlob(csvString, MimeType.MICROSOFT_EXCEL_LEGACY);
blob.setName(xlsName + ".xls");
driveFolder.createFile(blob);
};
function toCsv(arr) {
return arr.map(row =>
row.map(val => val).join(';')
).join('\n');
};
Am I missing something here, or is there no wat around putting the data in a sheet first and converting that sheet to xls?
Thank you!
I have implemented reading and converting to CSV from Excel File using Apache POI library successfully (where file is present in any of my local Windows folder) .
In my current scenario, I have to read the file from cloud storage bucket (gs://xyz/abc.xlsx),convert to CSV and store the file back to GCS.
Is there any way by which I can make my code identify the file present in Google Cloud?
Any leads will be appreciated.
There are Java APIs to communicate with GCS but I'm finding any way around to provide the path of GCS File to parameterized constructor of 'XSSFWorkbook'. Please find the snippet below which I'm using for converting an Excel file to CSV.
Workbook wb = new XSSFWorkbook(new File("C:\\Users\\balajeev\\Desktop\\abc.xlsx"));
DataFormatter formatter = new DataFormatter();
PrintStream out = new PrintStream(new FileOutputStream("C:\\Users\\balajeev\\Desktop\\abc.csv"),
true);
for (Sheet sheet : wb) {
for (Row row : sheet) {
boolean firstCell = true;
for (Cell cell : row) {
if ( ! firstCell ) out.print(',');
String text = formatter.formatCellValue(cell);
out.print(text);
firstCell = false;
}
out.println();
}
}
How to make this code recognise a file present in GCS,convert it to CSV and post conversion put the converted file in GCS.
I want to store a large string in PDF document somewhere hidden. Right now I have a hidden text field in which I am writing that text. The problem is that when the string size increased upto 10MB I start getting OutOfMemory errors.
What will be the best way to store some large hidden string/text to PDF document using iTextSharp? That text/string should be retrieved later as well.
Such private data can be stored in PieceInfo dictionaries, also cf. David's answer to the OP's follow-up question.
This answer to the older question "Insert hidden digest in pdf using iText library" shows how to make use of PieceInfo dictionaries in general using iText/Java (differences to iTextSharp/C# should be minimal here).
As the OP talks about data 10 MB and up, he may want to use PDF streams instead of strings.
The DocumentPieceInfo helper class provided in that older answer can be used with PDF streams for BIG DATA like this (again in Java as I'm mostly living on the Java side, and again porting to C# should be easy):
Storing document PieceInfo data
PdfName appName = new PdfName("MYAPP");
PdfName dataName = new PdfName("BigData");
DocumentPieceInfo dpi = new DocumentPieceInfo();
PdfReader reader = new PdfReader(...);
PdfStamper stamper = new PdfStamper(reader, ...);
InputStream in = ... BIG DATA INPUT STREAM ...;
PdfStream stream = new PdfStream(in, stamper.getWriter());
stream.flateCompress();
PdfIndirectObject ref = stamper.getWriter().addToBody(stream);
stream.writeLength();
in.close();
dpi.addPieceInfo(reader, appName, dataName, ref.getIndirectReference());
stamper.close();
Retrieving document PieceInfo data
PdfName appName = new PdfName("MYAPP");
PdfName dataName = new PdfName("BigData");
DocumentPieceInfo dpi = new DocumentPieceInfo();
PdfReader reader = new PdfReader("target/test-outputs/test-with-piece-info.pdf");
PdfObject myDataObject = dpi.getPieceInfo(reader, appName, dataName);
myDataObject = PdfReader.getPdfObject(myDataObject);
byte[] myData = PdfReader.getStreamBytes((PRStream)myDataObject)
As we know WPF OpenFileDialog no more changes the app's working directory and RestoreDirectory property is "unimplemented". However, upon subsequent open, its initial directory is default to the last opened file rather than the original working directory, so this information must be stored somewhere. I wonder is it possible to get/set it from user code?
On Windows 7 the recent file information is stored in the registry at this key:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Comdlg32\OpenSaveMRU
Beneath this key are subkeys for the various file extensions (e.g., exe, docx, py, etc).
Now, if you want to read these values, this will get a list of all paths stored beneath the subkeys (adapted from here):
String mru = #"Software\Microsoft\Windows\CurrentVersion\Explorer\ComDlg32\OpenSavePidlMRU";
RegistryKey rk = Registry.CurrentUser.OpenSubKey(mru);
List<string> filePaths = new List<string>();
foreach (string skName in rk.GetSubKeyNames())
{
RegistryKey sk = rk.OpenSubKey(skName);
object value = sk.GetValue("0");
if (value == null)
throw new NullReferenceException();
byte[] data = (byte[])(value);
IntPtr p = Marshal.AllocHGlobal(data.Length);
Marshal.Copy(data, 0, p, data.Length);
// get number of data;
UInt32 cidl = (UInt32)Marshal.ReadInt16(p);
// get parent folder
UIntPtr parentpidl = (UIntPtr)((UInt32)p);
StringBuilder path = new StringBuilder(256);
SHGetPathFromIDListW(parentpidl, path);
Marshal.Release(p);
filePaths.Add(path.ToString());
}
References:
http://social.msdn.microsoft.com/Forums/zh/vcmfcatl/thread/bfd89fd3-8dc7-4661-9878-1d8a1bf62697
Getting the last opened file in fileopen dialog box
http://social.msdn.microsoft.com/Forums/en/csharpgeneral/thread/c43ddefb-1274-4ceb-9cda-c78d860b687c)
I need a method that downloads a picture and save it in SD card for later use. I got it finally, i just need an operation that checks if the file in already exists or not.
If not, the app will download it. If it is exitsts, my image view will use it.
So my question is just simple:
How to check a file in SD?
If i got this place for example:
String imageInSD = "/sdcard/1.png";
You can use the following code
String sdcardState = android.os.Environment.getExternalStorageState();
String fileName = "yourfilename" + ".png";
if (sdcardState.contentEquals(android.os.Environment.MEDIA_MOUNTED))
{
String destPath = android.os.Environment.getExternalStorageDirectory().toString()+ File.separator +fileName;
File output =new File(destPath);
if(output.exists())
\\it exists-use Imageview
else
\\Download the file accordingly
}
else
\\SDCARD not mounted