예제 #1
0
        private DataTable CreateTable(UploadImagesModel uploadImagesModel, List <MultipartFileData> MultipartFileData, string fileUploadPath, string imgUrl)
        {
            _dtName = new DataTable();
            _dtName.Columns.Add("UserID");
            _dtName.Columns.Add("ImageUrl");
            _dtName.Columns.Add("ImageName");
            _dtName.Columns.Add("ImageContent", typeof(byte[]));

            DataRow newDataRow = null;

            foreach (MultipartFileData fileContent in MultipartFileData)
            {
                ContentDispositionHeaderValue contentDispositionValue = fileContent.Headers.ContentDisposition;
                string Name = UnquoteToken(contentDispositionValue.Name) ?? String.Empty;
                uploadImagesModel.ImageName = UnquoteToken(contentDispositionValue.FileName) ?? String.Empty;
                fileUploadPath = fileContent.LocalFileName;
                newDataRow     = _dtName.NewRow();

                uploadImagesModel.ImageContent = File.ReadAllBytes(fileUploadPath);
                newDataRow = ReturnDataRow(uploadImagesModel.UserID, imgUrl + @"\" + uploadImagesModel.ImageName, uploadImagesModel.ImageContent, uploadImagesModel.ImageName, uploadImagesModel.Description);
                _dtName.Rows.Add(newDataRow);
            }

            return(_dtName);
        }
예제 #2
0
        public async Task <Tuple <bool, string> > SaveImages(MultipartFormDataStreamProvider multipartFormDataStreamProvider, System.Web.HttpFileCollection hfc, string fileUploadPath)
        {
            UploadImagesModel    uploadImagesModel = new UploadImagesModel();
            Tuple <bool, string> resTuple          = null;
            int saveImgStatus = -1;

            try
            {
                int iUploadedCnt = 0;
                var formData     = multipartFormDataStreamProvider.FormData;
                foreach (var prop in typeof(UploadImagesModel).GetProperties())
                {
                    var curVal = formData[prop.Name];

                    if (curVal != null && !string.IsNullOrEmpty(curVal))
                    {
                        prop.SetValue(uploadImagesModel, To(curVal, prop.PropertyType), null);
                    }
                }

                if (!Directory.Exists(InstitutionImagesPath + uploadImagesModel.UserID))
                {
                    Directory.CreateDirectory(InstitutionImagesPath + uploadImagesModel.UserID);
                }

                for (int iCnt = 0; iCnt <= hfc.Count - 1; iCnt++)
                {
                    System.Web.HttpPostedFile hpf = hfc[iCnt];

                    if (hpf.ContentLength > 0)
                    {
                        if (!File.Exists(InstitutionImagesPath + uploadImagesModel.UserID + "\\" + Path.GetFileName(hpf.FileName)))
                        {
                            hpf.SaveAs(InstitutionImagesPath + uploadImagesModel.UserID + "\\" + Path.GetFileName(hpf.FileName));
                            iUploadedCnt = iUploadedCnt + 1;
                        }
                    }
                }

                using (SqlConnection cxn = new SqlConnection(_dcDb))
                {
                    var parameters = new DynamicParameters();
                    parameters.Add("@UserID", uploadImagesModel.UserID, DbType.Int32);
                    parameters.Add("@Description", uploadImagesModel.Description, DbType.String);
                    parameters.Add("@InstituteImgDocumentTable", CreateTable(uploadImagesModel, multipartFormDataStreamProvider.FileData.ToList(), fileUploadPath, ImageUrlPath + uploadImagesModel.UserID).AsTableValuedParameter());
                    parameters.Add("@CreatedBy", UserID, DbType.Int32);

                    saveImgStatus = await cxn.ExecuteScalarAsync <int>("dbo.Insert_InstituteImage", parameters, commandType : CommandType.StoredProcedure);
                }

                resTuple = Tuple.Create(true, "Created successfully");
            }
            catch (Exception ex)
            {
                ErrorLog.Write(ex);
            }
            return(resTuple);
        }
예제 #3
0
        public List <UploadImagesModel> GetImagesPath(String folderName)
        {
            DirectoryInfo Folder;

            FileInfo[]               Images;
            UploadImagesModel        obj       = new UploadImagesModel();
            List <UploadImagesModel> lstImages = new List <UploadImagesModel>();

            Folder = new DirectoryInfo(folderName);
            Images = Folder.GetFiles();
            List <String> imagesList = new List <String>();

            for (int i = 0; i < Images.Length; i++)
            {
                obj.ImageUrl  = String.Format(@"{0}/{1}", folderName, Images[i].Name);
                obj.ImageName = Images[i].Name;
                obj.ImageName = Images[i].Name;
                lstImages.Add(obj);
            }

            return(lstImages);
        }