Here is my code to upload file in cloud service (azure).
But its not getting into if condition. Its directly executing catch block.. i.e "ERROR OCCURRED WHILE UPLOAD FILE"
Please help me.
public partial class Fileupload : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
gvbind();
}
filestore fs = new filestore();
private static string parseUsingPDFBox(string filename)
{
org.apache.pdfbox.pdmodel.PDDocument doc = PDDocument.load(filename);
PDFTextStripper stripper = new PDFTextStripper();
string text = stripper.getText(doc);
doc.close();
return text;
}
string filecontent;
string encrypt;
string encrypt1;
string encrypt2;
string encrypt3;
protected void Button1_Click(object sender, EventArgs e)
{
try
{
if (FileUpload1.HasFile)
{
string _fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
if (_fileExt.ToLower() == ".docx" || _fileExt.ToLower() == ".txt" || _fileExt.ToLower() == ".doc" || _fileExt.ToLower() == ".pdf")
{
string Index = string.Empty;
try
{
SetContainerAndPermissions();
}
catch
{
}
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("BlobConn"));
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
Index = Guid.NewGuid().ToString();
string uploadedDocName = "Document_" + Index + "#" + FileUpload1.PostedFile.FileName;
CloudBlockBlob blob = container.GetBlockBlobReference(uploadedDocName);
blob.Metadata["FileType"] = FileUpload1.PostedFile.ContentType;
blob.Properties.ContentType = FileUpload1.PostedFile.FileName;
blob.UploadFromStream(FileUpload1.FileContent);
Connection ins = new Connection();
int result = ins.insert(FileUpload1.PostedFile.FileName.ToString(), blob.Uri.ToString(), FileUpload1.PostedFile.ContentLength.ToString() + " bytes", FileUpload1.PostedFile.ContentType.ToString(), Index, DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString(), "UnBlocked",Session["username"].ToString());
string filename = Path.GetFileName(FileUpload1.FileName);
FileUpload1.SaveAs(Server.MapPath("~/") + filename);
string strFileName = System.IO.Path.GetFullPath(Server.MapPath("~/" + filename));
string e1 = Path.GetExtension(strFileName);
if (e1.ToLower() == ".pdf")
{
string file = parseUsingPDFBox(strFileName);
file = file.Replace("'", "''");
byte[] mybyte = System.Text.Encoding.UTF8.GetBytes(file);
string returntext = System.Convert.ToBase64String(mybyte);
encrypt = returntext;
byte[] mybyte1 = System.Convert.FromBase64String(returntext);
string returntext1 = System.Text.Encoding.UTF8.GetString(mybyte);
filecontent = returntext1;
int len = returntext.Length;
int split = len / 3;
string[] word = new string[3];
int j = 0;
int i;
int h;
int g;
word[0] += returntext.Substring(0, split);
word[1] += returntext.Substring(split, split);
word[2] += returntext.Substring(split + split, split);
encrypt1 = word[0];
encrypt2 = word[1];
encrypt3 = word[2];
}
string scret = GetRandomString();
fs.upload(FileUpload1.PostedFile.FileName.ToString(), blob.Uri.ToString(), filecontent, encrypt, encrypt1, encrypt2, encrypt3, scret,Session["username"].ToString());
Label1.Text = "Thank you! Your File Upload Successfully.";
Label1.ForeColor = System.Drawing.Color.Black;
gvbind();
}
else
{
Label1.Text = "Please Select Valid Files to Upload";
}
}
else
{
Label1.Text = "Please Select any Files to Upload";
Label1.ForeColor = System.Drawing.Color.Red;
}
}
catch
{
Label1.Text = "Sorry! Error occured while upload your Files.";
Label1.ForeColor = System.Drawing.Color.Red;
}
}
But, this same code previously woking in VS 2010.
But now its not working in VS 2013.
WHy?
Help me?