I know that this question was asked many times here before and I read it , but I can't find a solution to my problem. I'm trying to save image to the folder in my project :
here is my code behind :
if (FileUpload_UploadFile.HasFile)
{
int contentLength = FileUpload_UploadFile.PostedFile.ContentLength;
string contentType = FileUpload_UploadFile.PostedFile.ContentType;
string fileName = FileUpload_UploadFile.PostedFile.FileName;
string imgPath = "~/Image/" + fileName ;
FileUpload_UploadFile.PostedFile.SaveAs(Server.MapPath(imgPath));
}
and this is the stack trace :
[DirectoryNotFoundException: Could not find a part of the path 'C:\Users\.bimanathan\Desktop\PETA\PETA\Image\0eaf985f79f0ceff94aa8c585a31f745_650x.jpg'.]
System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) +359
System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) +1305
System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) +60
System.IO.FileStream..ctor(String path, FileMode mode) +55
System.Web.HttpPostedFile.SaveAs(String filename) +94
PETA.CreateNews.btnSubmit_Click(Object sender, EventArgs e) in c:\Users\.bimanathan\Desktop\PETA\PETA\TEST\CreateNews.aspx.cs:73
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9628026
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
I don't know how to fix it please help me.
I am beginner in c#
Drop the tilde from the /image/ path. Server.MapPath does not use it.
eg:
string imgPath = "/Image/" + fileName ;
See here for a table of relative expressions for paths: https://msdn.microsoft.com/en-us/library/system.web.httpserverutility.mappath%28v=vs.110%29.aspx
The user running the www service needs to have write permissions to the location in question. often this user is a service, not an interactive user. Confirm that the service user has appropriate read and write permissions.
Also, be particularly careful about allowing users to upload documents into the site directory hierarchy itself. It requires that your default permissions allow write to your site root, which can be misused in many ways.
To make sure the path is constructed in a correct way I always use Path.Combine(String, String)
System.IO.Path.Combine("/Image/", fileName);
If you use web,you can use VirtualPathUtility(String, String)
System.Web.VirtualPathUtility.Combine("~/Image/", fileName)
Related
I have Sitecore instance 6.6 updated from 6.3. After the update an exception occurs when right-clicking on the left side of the content tree. That's the space where you can choose to show the lock icon and so on. Here's a screenshot:
This is the error message:
[ArgumentException: Empty strings are not allowed.
Parametername: header]
Sitecore.Diagnostics.Assert.ArgumentNotNullOrEmpty(String argument, String argumentName) +241
Sitecore.Web.UI.HtmlControls.Menu.Add(String id, String header, String icon, String hotkey, String click, Boolean check, String radiogroup, MenuItemType type) +68
Sitecore.Shell.Applications.ContentManager.ContentEditorForm.Gutter_ContextMenu() +637
[TargetInvocationException: Ein Aufrufziel hat einen Ausnahmefehler verursacht.]
System.RuntimeMethodHandle._InvokeMethodFast(Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeTypeHandle typeOwner) +0
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean skipVisibilityChecks) +808
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +38
Sitecore.Shell.Framework.Commands.MethodCommandProcessor.Invoke(PipelineArgs args) +427
Sitecore.Nexus.Pipelines.NexusPipelineApi.Resume(PipelineArgs args, Pipeline pipeline) +330
Sitecore.Pipelines.Pipeline.DoStart(PipelineArgs args) +208
Sitecore.Pipelines.Pipeline.Start(PipelineArgs args, Boolean atomic) +182
Sitecore.Shell.Framework.Commands.MethodCommand.Execute(CommandContext context) +499
Sitecore.Web.UI.Sheer.ClientPage.OnPreRender(EventArgs e) +530
Sitecore.Shell.Applications.ContentManager.ContentEditorPage.OnPreRender(EventArgs e) +25
System.Web.UI.Control.PreRenderRecursiveInternal() +108
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3394
Any idea how I can fix this?
There's a couple of things you need to check and doublecheck.
1) Is your Sitecore.Kernel.dll in /bin the correct version for 6.6. A very common mistake to make is, to go through the upgrade fine and then rebuild your project - forgetting that your local obj and bin folders hold Sitecore DLLs for 6.3 that then gets copied to /bin.
To fix this, first try and take the entire /bin directory from your 6.6 zip and copy/replace it to your website /bin. See if the issues goes away.
2) If not, check our commands.config (located in App_Config/Include) and make sure it's the right version for 6.6.
These two, is where I would start looking first.
I found out what caused this error. The items in the core database of that menu lost their language versions during the update. After creating the language versions of those items in the core db, the menu shows up again.
i got the following error when uploaded my files to AppHarbor
[HttpCompileException]: d:\temp\f3fkwz4z.mbc\temp\root\0c956e8e\9304c5fb\App_Web_ixu4pbnj.0.cs(43): error CS1009: Unrecognized escape sequence
at System.Web.Compilation.AssemblyBuilder.Compile()
at System.Web.Compilation.WebDirectoryBatchCompiler.CompileAssemblyBuilder(AssemblyBuilder builder)
at System.Web.Compilation.WebDirectoryBatchCompiler.<CompileNonDependentBuildProviders>b__0(AssemblyBuilder assemblyBuilder)
at System.Web.Compilation.CompilationUtil.CompileParallel(ICollection assemblyBuilders, Action`1 action)
at System.Web.Compilation.WebDirectoryBatchCompiler.CompileNonDependentBuildProviders(ICollection buildProviders)
at System.Web.Compilation.WebDirectoryBatchCompiler.Process()
at System.Web.Compilation.BuildManager.BatchCompileWebDirectoryInternal(VirtualDirectory vdir, Boolean ignoreErrors)
at System.Web.Compilation.BuildManager.BatchCompileWebDirectory(VirtualDirectory vdir, VirtualPath virtualDir, Boolean ignoreErrors)
at System.Web.Compilation.BuildManager.PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, Boolean topLevel)
at System.Web.Compilation.BuildManager.PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, Boolean topLevel)
at System.Web.Compilation.BuildManager.PrecompileWebDirectoriesRecursive(VirtualDirectory vdir, Boolean topLevel)
at System.Web.Compilation.BuildManager.PrecompileAppInternal(VirtualPath startingVirtualDir, IEnumerable`1 excludedVirtualPaths)
at System.Web.Compilation.BuildManager.PrecompileApp(VirtualPath startingVirtualDir, IEnumerable`1 excludedVirtualPaths)
at System.Web.Compilation.BuildManager.PrecompileApp(ClientBuildManagerCallback callback, IEnumerable`1 excludedVirtualPaths)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback, List`1 excludedVirtualPaths)
at System.Web.Compilation.BuildManagerHost.PrecompileApp(ClientBuildManagerCallback callback, List`1 excludedVirtualPaths)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback, Boolean forceCleanBuild)
at System.Web.Compilation.ClientBuildManager.PrecompileApplication(ClientBuildManagerCallback callback)
at System.Web.Compilation.Precompiler.Main(String[] args)
although no such file exist in my project it is Asp.Net MVC4 project with EntityFramework
i dont understand from where the error comes
That strange file name that you are seeing is AppHarbor compiling your cshtml/vbhtml files when you deploy. Any errors in those files (bad Model property calls, even bad HTML) can cause the build to fail on those files and provide some pretty cryptic errors.
Try setting the MvcBuildViews property to true (Here is how to do that via Phil Haack) and see if you can use Visual Studio to help localize and correct the error.
I have a MVC 4 Project (Company.Project.WebUI), a project for all my model classes (Company.Project.Data) and a project for the DAL (Company.Project.Services).
How can I manage this with Code First Migrations?
I'm getting the following error when I write the command Add-Migration Init:
`
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.RuntimeModule.GetTypes()
at System.Reflection.Assembly.GetTypes()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
`
When I write the command Add-Migration -StartUpProjectName "Company.Project.Services" Init I'll get also an error
`
System.IO.FileNotFoundException: Could not load file or assembly 'Company.Project.WebUI' or one of its dependencies. The system cannot find the file specified.
File name: 'Company.Project.WebUI'
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.FindConfiguration()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.GetMigrator()
at System.Data.Entity.Migrations.Design.ToolingFacade.GetPendingMigrationsRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
`
Could somebody tell me what's the best way to use EF Code First Migration with different dlls?
I don't know why, but EF wants your DAL project to be set as the start up project in Visual Studio. I just had the same error and this solved the problem.
On Solution Explorer: Right Click to your DAL project -> select "Set as StartUp Project".
We are concurrently developing Android and iPhone apps and the core code (written in C#) is shared between them. The SQLite database initialization code, for example, is the same in both apps with only slight variations to accommodate the file structure on each platform. The following code is working in MonoTouch, but throws an EntryPointNotFoundException in Mono for Android:
try
{
System.Data.Common.DbDataAdapter adapter = new SqliteDataAdapter(selectCommand);
retVal = adapter.Fill(dataSet);
}
catch (Exception exception)
{
...
}
As far as I can tell, the selectCommand and dataSet objects are identical on both platforms The message and stack trace are as follows:
> System.EntryPointNotFoundException: sqlite3_column_origin_name at (wrapper managed-to-native) Mono.Data.Sqlite.UnsafeNativeMethods:sqlite3_column_origin_name (intptr,int)
at Mono.Data.Sqlite.SQLite3.ColumnOriginalName (Mono.Data.Sqlite.SqliteStatement stmt, Int32 index) [0x00000] in /home/jon/Development/xamarin/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLite3.cs:493
at Mono.Data.Sqlite.SqliteDataReader.GetSchemaTable (Boolean wantUniqueInfo, Boolean wantDefaultValue) [0x0042d] in /home/jon/Development/xamarin/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDa>taReader.cs:619
at Mono.Data.Sqlite.SqliteDataReader.GetSchemaTable () [0x00000] in /home/jon/Development/xamarin/mono/mcs/class/Mono.Data.Sqlite/Mono.Data.Sqlite_2.0/SQLiteDataReader.cs:550
at System.Data.Common.DataAdapter.BuildSchema (IDataReader reader, System.Data.DataTable table, SchemaType schemaType, MissingSchemaAction missingSchAction, MissingMappingAction missingMapAction, System.Data.Common.DataTableMappingCollection dtMapping) [0x0003b] in /home/jon/Development/xamarin/mono/mcs/class/System.Data/System.Data.Common/DataAdapter.cs:284
at System.Data.Common.DataAdapter.BuildSchema (IDataReader reader, System.Data.DataTable table, SchemaType schemaType) [0x00000] in /home/jon/Development/xamarin/mono/mcs/class/System.Data/System.Data.Common/DataAdapter.cs:257
at System.Data.Common.DataAdapter.FillTable (System.Data.DataTable dataTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords, System.Int32& counter) [0x00011] in /home/jon/Development/xamarin/mono/mcs/class/System.Data/System.Data.Common/DataAdapter.cs:428
at System.Data.Common.DataAdapter.FillInternal (System.Data.DataSet dataSet, System.String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) [0x0009b] in /home/jon/Development/xamarin/mono/mcs/class/System.Data/System.Data.Common/DataAdapter.cs:533
at System.Data.Common.DataAdapter.Fill (System.Data.DataSet dataSet, System.String srcTable, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) [0x00000] in /home/jon/Development/xamarin/mono/mcs/class/System.Data/System.Data.Common/DataAdapter.cs:589
at System.Data.Common.DbDataAdapter.Fill (System.Data.DataSet dataSet, Int32 startRecord, Int32 maxRecords, System.String srcTable, IDbCommand command, CommandBehavior behavior) [0x0004e] in /home/jon/Development/xamarin/mono/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs:337
at System.Data.Common.DbDataAdapter.Fill (System.Data.DataSet dataSet) [0x00000] in /home/jon/Development/xamarin/mono/mcs/class/System.Data/System.Data.Common/DbDataAdapter.cs:265
at Core.Database.ServerCommunicate.FillDataSet (Core.Database.XCommand selectCommand, System.Data.DataSet& dataSet) [0x00013] in /Users/sstream6/sd/110/core/Asm/Db/Database/Server.cs:648
I have verified on both platforms that the database has been created and a connection established. Has anyone else experienced similar problems?
Unfortunately Android's SQLite library doesn't include support for the sqlite3_column_origin_name() method, so any parts of Mono.Data.Sqlite that depend on it are going to fail. Xamarin has a bug tracked here for modifying the implementation to get around the limitation, but there's no timeframe on it yet as far as I know.
I created a MVC 2 Application to work as a RSS Feeder and deliver News Contents for a number of applications to consume.
Everything was doing fine until yesterday when suddenly my application started throwing a random error which doesn't tell me much of what's going on (or at least I don't understand it).
This error only occurs in Production and cannot be reproduced in staging or my local machine.
Here's the stack trace:
Error executing child request for handler
'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerWrapper'.errorPath:/Android/Edition/2011-11-22/P1
HostIP:##.##.##.## at
System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler,
TextWriter writer, Boolean preserveForm, Boolean setPreviousPage,
VirtualPath path, VirtualPath filePath, String physPath, Exception
error, String queryStringOverride) at
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter
writer, Boolean preserveForm, Boolean setPreviousPage) at
System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter
writer, Boolean preserveForm) at
System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler,
TextWriter writer, Boolean preserveForm) at
System.Web.Mvc.ViewPage.RenderView(ViewContext viewContext) at
System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.<>c_DisplayClass14.b_11()
at
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter
filter, ResultExecutingContext preContext, Func1 continuation) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter
filter, ResultExecutingContext preContext, Func1 continuation) at
System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext
controllerContext, IList1 filters, ActionResult actionResult) at
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext
controllerContext, String actionName) at
System.Web.Mvc.Controller.ExecuteCore() at
System.Web.Mvc.MvcHandler.<>c__DisplayClass8.b__4() at
System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass1.b__0() at
System.Web.Mvc.Async.AsyncResultWrapper.<>c__DisplayClass81.b__7(IAsyncResult
_) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.End() at
System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step,
Boolean& completedSynchronously)
This error only occurs sometimes and can throw at any action of any controller.
I would like to have found the reason in a specific action but it only throws sometimes and can throw for any action.
Such byzantine errors are hard to debug. The stack trace you're seeing does not help in diagnosing the error.
First, you should improve error logging. In your global.asax, create an implementation of the Application_Error hook that logs the exception and all inner exceptions to a file (I wouldn't log this to the database, because the db connection could be the culprit). Make sure that this code is solid: it should focus on these critical errors and not log every 404 page. Also, make sure that the logging code itself does not create any problems (it should be highly error tolerant).
The cause for this kind of problems is usually access to some kind of static variables. Out of all keywords, I believe static is by far the most dangerous one because it is so subtle.
Some common errors I've seen.
Caching Someone wanted to be smart and cache some data in a static dictionary or so. Unfortunately, the locking code is flawed. An exception occurs only if the code for some user tries to add sth. to the cache, but it's already there:
if(_dict.ContainsKey(cacheKey) == false)
{
// second thread adds data to the dictionary here
_dict.Add(cacheKey, cacheData); // exception
}
This can also happen in a 3rd party library that uses caching or pooling. Access static variables with care.
Uncommon Code Paths Something unusual happens that calls code that is not called very often, and that code is flawed. If you have testing with high code coverage, check the spots that are not covered by the tests.
DB Connection Lost A socket reset on the db connection could lead to exceptions. Many database connection libraries / drivers fix this quickly (i.e. the next request will be fine). This is hard to handle; basically it shouldn't happen but there are many reasons why it could occur.
This error tells you, that the true error is somewhere in some child action, that is action rendered by Html.RenderAction().
There is no such thing as "random" error - there has to be scenario where it happens, you just dont know it because the conditions vary maybe.
You should identify all your child actions, and test them with various inputs.. after you identify the problematic input set, try disabling child actions one by one and find the error this way.