public string getMultimediaFile(int id, string gxdbFileUri) { if (!GXDbFile.IsFileExternal(gxdbFileUri)) { string fileName = GXDbFile.GetFileNameFromUri(gxdbFileUri); if (!String.IsNullOrEmpty(fileName)) { string filePath = Path.Combine(_gxDbCommand.Conn.MultimediaPath, fileName); try { GxFile file = new GxFile(string.Empty, filePath, GxFileType.PublicAttribute); if (file.Exists()) { return(file.GetURI()); } else { return(getBLOBFile(id, FileUtil.GetFileType(gxdbFileUri), FileUtil.GetFileName(gxdbFileUri), filePath, false, GxFileType.PublicAttribute)); } } catch (ArgumentException) { return(""); } } } return(""); }
public short Open(String fileName) { OpenFromTemplate = false; try { if (!string.IsNullOrWhiteSpace(template)) { GxFile temp = new GxFile(Path.GetDirectoryName(template), template); if (temp.Exists()) { GXLogging.Debug(log, "Opening Template " + template); p = new ExcelPackage(temp.GetStream()); OpenFromTemplate = true; } else { errCod = 4; errDescription = "Invalid template."; return(errCod); } } else { GxFile file = new GxFile(fileName, fileName, GxFileType.Private); if (string.IsNullOrEmpty(Path.GetExtension(fileName)) && !file.Exists()) { fileName += Constants.EXCEL2007Extension; } if (file.IsExternalFile) { p = new ExcelPackage(file.GetStream()); } else { p = new ExcelPackage(new FileInfo(fileName)); } } workBook = (ExcelWorkbook)p.Workbook; workBook.CalcMode = ExcelCalcMode.Automatic; this.selectFirstSheet(); xlsFileName = fileName.ToString(); } catch (Exception e) { GXLogging.Error(log, "Error opening " + fileName, e); errCod = 10; errDescription = "Could not open file." + e.Message + (e.InnerException != null ? e.InnerException.Message : ""); return(errCod); } return(0); }
public short Open(String fileName) { try { GXLogging.Debug(log, "GetType " + nmspace + ".ExcelFile"); Type classType = ass.GetType(nmspace + ".ExcelFile", false, true); ef = Activator.CreateInstance(classType); GxFile file = new GxFile(Path.GetDirectoryName(fileName), fileName, GxFileType.Private); if (!String.IsNullOrEmpty(template)) { GxFile templateFile = new GxFile(Path.GetDirectoryName(template), template); if (templateFile.Exists()) { GXLogging.Debug(log, "Opening Template " + template); var stream = templateFile.GetStream(); stream.Position = 0; GxExcelUtils.Invoke(ef, "LoadXls", new object[] { stream }); } else { errCod = 4; errDescription = "Invalid template."; return(errCod); } } else if (file.Exists()) { var stream = file.GetStream(); stream.Position = 0; GxExcelUtils.Invoke(ef, "LoadXls", new object[] { stream }); } else { object worksheets = GxExcelUtils.GetPropValue(ef, "Worksheets"); object ws = GxExcelUtils.Invoke(worksheets, "Add", new object[] { "Sheet1" }); GxExcelUtils.SetPropValue(worksheets, "ActiveWorksheet", ws); } xlsFileName = fileName; } catch (Exception e) { GXLogging.Error(log, "Error opening " + fileName, e); errCod = 10; errDescription = "Could not open file." + e.Message + (e.InnerException != null ? e.InnerException.Message:""); return(errCod); } return(0); }
public bool FromJSonFile(GxFile file, GXBaseCollection <SdtMessages_Message> Messages) { if (file != null && file.Exists()) { string s = file.ReadAllText(string.Empty); return(FromJSonString(s, Messages)); } else { GXUtil.ErrorToMessages("FromJSon Error", "File does not exist", Messages); return(false); } }
private string getBLOBFile(int id, string extension, string name, string fileName, bool temporary, GxFileType fileType = GxFileType.PrivateAttribute) { GxFile file = null; Stream fs = null; BinaryWriter bw = null; int bufferSize = 4096; byte[] outbyte = new byte[bufferSize]; long retval; long startIndex = 0; bool streamClosed = false; try { startIndex = 0; retval = _gxDbCommand.Db.GetBytes(_gxDbCommand, _DR, id - 1, startIndex, outbyte, 0, bufferSize); if (retval == 0) { return(""); } using (fs = new MemoryStream()) { using (bw = new BinaryWriter(fs)) { while (retval == bufferSize) { bw.Write(outbyte); bw.Flush(); startIndex += bufferSize; retval = _gxDbCommand.Db.GetBytes(_gxDbCommand, _DR, id - 1, startIndex, outbyte, 0, bufferSize); } bw.Write(outbyte, 0, (int)retval); bw.Flush(); fs.Seek(0, SeekOrigin.Begin); file = new GxFile(_gxDbCommand.Conn.BlobPath, fileName, fileType); file.Create(fs); } } streamClosed = true; GXLogging.Debug(log, "GetBlobFile fileName:" + fileName + ", retval bytes:" + retval); if (temporary) { GXFileWatcher.Instance.AddTemporaryFile(file); } fileName = file.GetURI(); } catch (IOException e) { if (!file.Exists()) { GXLogging.Error(log, "Return getBLOBFile Error Can't read BLOB field into " + fileName, e); throw (new GxADODataException(e)); } else { GXLogging.Warn(log, "Return getBLOBFile Error Can't write BLOB field into " + fileName, e); } } finally { if (!streamClosed) { try { if (bw != null) { bw.Close(); } if (fs != null) { fs.Close(); } } catch (Exception ex) { GXLogging.Error(log, "getBLOBFile Close Stream Error", ex); } } } return(fileName); }