Where to start?
Quote:
string fileName = DisplayFileName.FileName.Replace(".xlsx", "-") + Guid.NewGuid().ToString() + ".xlsx";
Should be:
string fileName = Path.GetFileNameWithoutExtension(DisplayFileName.FileName) + "-" + Guid.NewGuid().ToString() + Path.GetExtension(DisplayFileName.FileName);
Quote:
string DirectoryCreate = myValue1 + "\\" + Month + "\\" + fileName;
string exportDirectory = myValue2 + "\\" + Month;
string exportPath = myValue2 + "\\" + Month + "\\" + fileName;
You should probably be using
Path.Combine
here - eg:
string DirectoryCreate = Path.Combine(myValue1, Month, fileName);
Also
myValue1
and
myValue2
are not defined anywhere.
Quote:
var filedata = ContentDispositionHeaderValue.Parse(Request.Form.Files[0].ContentDisposition).FileName.Trim('"');
You already have the file name -
DisplayFileName.FileName
. You don't need to parse the
ContentDisposition
header to extract it again.
Quote:
GC.Collect();
That is almost always the wrong thing to do - especially in a multi-user environment like ASP.NET.
Quote:
throw new Exception("Ok so the error message IS right.");
You should be throwing a more specific exception type, and providing a meaningful message here.
Quote:
SqlConnection con;
Why have you declared this variable when you never use it?
I'm sure there would be plenty of other problems if we knew what the code was supposed to be doing.