private DataTable ConvertRCPAExcelToDataTable(System.Web.HttpPostedFileBase postedFile) { IFileProvider fileProvider = new FileSystemProvider(); IExcelFactory excelFactory = new ExcelFactory(); CurrentInfo objCurInfo = new CurrentInfo(); string containerName = objCurInfo.GetCompanyCode().ToLower(); string fileName = postedFile.FileName; string[] excelRetrieveColumns = new string[] { "*" }; _employeeExcelTemplateFileName = fileProvider.GetFilePathToSave(UPLOAD_PATH_KEY_NAME, fileName); string whereQuery = " LEN(Region_Name) >0 "; // postedFile.SaveAs(_employeeExcelTemplateFileName); DataControl.Repository.AzureBlobUpload objAzureUpload = new Repository.AzureBlobUpload(); DataControl.Abstraction.IFileProvider objPathProv = new DataControl.Impl.FileSystemProvider(); string accKey = objPathProv.GetConfigValue("UPLOADEDFILEBLOBACCKEY"); string blobURL = objAzureUpload.PutAzureBlobStorage(postedFile.InputStream, postedFile.FileName, accKey, containerName); System.IO.Stream stream = objAzureUpload.AzureblockDownload(postedFile.FileName, accKey, containerName); DataTable dt = new DataTable(); dt = objAzureUpload.ConvertStreamToDataTable(stream, "D_Doctor_Name"); return(dt); }
public string WriteCsvIntoBlob(DataTable dataTable, string accKey, string fileName) { MemoryStream stream = new MemoryStream(); CurrentInfo objCur = new CurrentInfo(); string containerName = objCur.GetCompanyCode().ToLower(); using (StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.Default)) { Repository.AzureBlobUpload objAzureBlob = new Repository.AzureBlobUpload(); objAzureBlob.PutAzureBlobStorage(stream, fileName, accKey, containerName); writer.Flush(); writer.Close(); } return(string.Empty); }
public string AzureBlopforChunkUpload(System.IO.Stream inputStream, string fileName, string containerName, string accountKey) { if (fileName != null) { Repository.AzureBlobUpload objAzureUpload = new Repository.AzureBlobUpload(); // string accKey = lstBlob[0].Blob_Access_Key;//iConfigPro.GetConfigValue(lstBlob[0].Blob_Access_Key); Microsoft.WindowsAzure.Storage.Blob.CloudBlobContainer container = objAzureUpload.GetBlobContainerObject(containerName, accountKey); container.CreateIfNotExists(); //to replace the file name with new GUID //string newfileName = Guid.NewGuid().ToString() + Path.GetExtension(fileName); // string newfileName = objBlInfra.GenerateFileName(fileName); container.SetPermissions(new Microsoft.WindowsAzure.Storage.Blob.BlobContainerPermissions { PublicAccess = Microsoft.WindowsAzure.Storage.Blob.BlobContainerPublicAccessType.Blob }); Microsoft.WindowsAzure.Storage.Blob.CloudBlockBlob blob = container.GetBlockBlobReference(fileName); int blockSize = 1024 * 1024; //256 kb using (Stream fileStream = inputStream) { long fileSize = fileStream.Length; //block count is the number of blocks + 1 for the last one int blockCount = (int)((float)fileSize / (float)blockSize) + 1; //List of block ids; the blocks will be committed in the order of this list List <string> blockIDs = new List <string>(); //starting block number - 1 int blockNumber = 0; try { int bytesRead = 0; //number of bytes read so far long bytesLeft = fileSize; //number of bytes left to read and upload //do until all of the bytes are uploaded while (bytesLeft > 0) { blockNumber++; int bytesToRead; if (bytesLeft >= blockSize) { //more than one block left, so put up another whole block bytesToRead = blockSize; } else { //less than one block left, read the rest of it bytesToRead = (int)bytesLeft; } //create a blockID from the block number, add it to the block ID list //the block ID is a base64 string string blockId = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("BlockId{0}", blockNumber.ToString("0000000")))); blockIDs.Add(blockId); //set up new buffer with the right size, and read that many bytes into it byte[] bytes = new byte[bytesToRead]; fileStream.Read(bytes, 0, bytesToRead); //calculate the MD5 hash of the byte array //string blockHash = GetMD5HashFromStream(bytes); var chunkStream = new MemoryStream(bytes); //upload the block, provide the hash so Azure can verify it blob.PutBlock(blockId, chunkStream, null, null, new Microsoft.WindowsAzure.Storage.Blob.BlobRequestOptions() { RetryPolicy = new Microsoft.WindowsAzure.Storage.RetryPolicies.LinearRetry(TimeSpan.FromSeconds(10), 3) }, null); //increment/decrement counters bytesRead += bytesToRead; bytesLeft -= bytesToRead; } //commit the blocks blob.PutBlockList(blockIDs); return(blob.Uri.ToString()); } catch (Exception ex) { System.Diagnostics.Debug.Print("Exception thrown = {0}", ex); return(null); } } } return(null); }