Here is my code.
private void uploadfile()
{
//ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('click trigger')", true);
if (fileFalg)
{
//ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('moving forward to chech the file')", true);
if (FileUpload1.HasFile)
{
// ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('have file')", true);
string file_Name = null;
try
{
// ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('i'm in try')", true);
string[] allowedfile = { ".txt" };
string fileEx = Path.GetExtension(FileUpload1.FileName);
bool isvalidFile = allowedfile.Contains(fileEx);
if (!isvalidFile)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "errale", "alert('Invalid File Type')", true);
}
else
{
// ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('testing')",true);
file_Name = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.SaveAs(Server.MapPath("~/Upload/" + file_Name));
string file_path = Path.GetFullPath(Server.MapPath("~/Upload/" + file_Name));
StreamReader reader = File.OpenText(file_path);
TextReader oku = new StreamReader(file_path);
// ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('file loaded')", true);
string s;
while ((s = oku.ReadLine()) != null)
{
ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('reading file')", true);
imeilist.Add(s);
ListBoxIMEI.Items.Add(s);
}
oku.Close();
SelectDataFromFileFlag = true;
}
}
catch (Exception ex) {
throw ex;
ScriptManager.RegisterClientScriptBlock(Page, typeof(Page), "ClientScript", "alert('opps got some problem')", true);
}
SelectDataFromFileFlag = true;
}
}
}
It runs perfect on Local host when run on server gives me following error.
Server Error in '/' Application.
Could not find a part of the path 'D:\home\site\wwwroot\Upload\testing.txt'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'D:\home\site\wwwroot\Upload\testing.txt'.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[DirectoryNotFoundException: Could not find a part of the path 'D:\home\site\wwwroot\Upload\testing.txt'.]
WebApplication1.MarkSales.uploadfile() in D:\projects\DMS\DMS_Web\WebApplication1\MarkSales.aspx.cs:317
WebApplication1.MarkSales.btnReadFile_Click(Object sender, EventArgs e) in D:\projects\DMS\DMS_Web\WebApplication1\MarkSales.aspx.cs:270
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9767618
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +204
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +12
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +15
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1738
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.2106.0
Looking for the solution on how to fix this issue.