Why does this File write fail after a SharePoint 2010 migration?
Solution 1
What are LOG_FILE_PATH and LOG_FILE_FORMAT?
The IO exception could be caused if either are empty or invalid in some other way.
Solution 2
It can even occur if you are trying to refer to a removable medium too frequently. In my case, I was trying to display the remaining space in the disk by getting the information from the DriveInfo.GetDrives()
method.
The code was called as soon as a few bytes were copied to the device. So, it's better to check if it's not the case. Do the exception handling and let it get the details when it is ready.
Related videos on Youtube
Shankar
Updated on May 26, 2022Comments
-
Shankar almost 2 years
I migrated my MOSS 2007 application (with custom approval workflow) to Sharepoint 2010. I had this generic piece of code to log data
private void WriteToLog(String logInfo) { SPSecurity.RunWithElevatedPrivileges(delegate() { File.AppendAllText(LOG_FILE_PATH + string.Format("{0:" + LOG_FILE_FORMAT + "}", DateTime.Now) + ".log", logInfo); }); }
I have done a database detach upgrade, there are running workflows (In progress state) from the previous environment which should continue in sharepoint 2010. But unfortunately that does not happen , my replicator activity threw an error. I found this in the sharepoint log
System.IO.IOException: The device is not ready.
at System.IO._Error.WinIOError(Int32 errorCode, String maybeFullP ath)
at System.IO.FileStream.Init(String p ath, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY atTRIBUTES sec attrs, String msgP ath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String p ath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgP ath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String p ath, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
at System.IO.StreamWriter..ctor(String p ath, Boolean append, Encoding encoding, Int32 bufferSize)
at System.IO.StreamWriter..ctor(String p ath, Boolean append, Encoding encoding)
at System.IO.File.AppendAllText(String p ath, String contents, Encoding encoding)
at xyz.Utils.MailNotific ations.DisplayClass1._0()
at Microsoft.SharePoint.SPSecurity.DisplayClass4._2()
at Microsoft.SharePoint.Utilities.SecurityContext.RunAsProcess(CodeToRunElev ated secureCode)
at Microsoft.SharePoint.SPSecurity.RunWithElev atedPrivileges(WaitCallback secureCode, Object param)
at Microsoft.SharePoint.SPSecurity.RunWithElev atedPrivileges(CodeToRunElev ated secureCode)
at xyz.Utils.MailNotific ations.WriteToLog(String logInfo)
at xyz.Utils.MailNotific ations.SPNotific ation(SPWeb applic ation, String subject, String approver, String htmlBody)
at xyz.WF.Approval.ApprovalWorkFlow.logError_ExecuteCode(Object sender, EventArgs e)
at System.Workflow.ComponentModel.Activity.RaiseEvent(DependencyProperty dependencyEvent, Object sender, EventArgs e)
at System.Workflow.Activities.CodeActivity.Execute(ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutor1.Execute(T activity, ActivityExecutionContext executionContext)
1.Execute(Activity activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutor
at System.Workflow.ComponentModel.ActivityExecutorOper ation.Run(IWorkflowCoreRuntime workflowCoreRuntime)
at System.Workflow.Runtime.Scheduler.Run()In brief this seems to be an IO exception. I have shared the log folder location, file access permission is ruled out, the application works just fine when a new workflow is started.
-
Shankar over 12 yearsI have these in my web.config file as <add key="LogFileFormat" value="MMyyyyHH" /><add key="LogFilePath" value="D:\Projects\xyz\Log\" />
-
Shankar over 12 yearsAnd when a new workflow is started, i get the log data properly.The problem is only when moving a running workflow that was initiated in MOSS 2007
-
Shankar over 12 yearsI had different log file paths set in my MOSS 2007 and SharePoint 2010 application. I replicated the folder structure from my MOSS 2007 machine in the new environment and i retained the log file path location in the configuration file. It worked! Thanks for your lead!