Can't move file , because is used by another process - asp.net

I have many files in one directory, My app, must move some files to another directory. When I did this, first time works fine, but after that I have a exception like:
System.IO.IOException: process cannot access the file because another process is using the file.
I close windows explorer, or any program, avoiding the use of the file, but the problem persists.
I move files in this way:
private void ExtractosRemover()
{
string dirOrigen = '\\' + #"\" + servidor + #"\" + "EEQ_" + User.Identity.Name.ToString() + #"\";
string dirDestin = '\\' + #"\" + servidor + #"\" + "FacturasMatch_" + User.Identity.Name.ToString() + #"\";
try
{
foreach (GridViewRow grd_Row in this.gvwExtractosMatch.Rows)
{
File.Move(System.IO.Path.Combine(dirOrigen, clean(grd_Row.Cells[7].Text) + ".xml"), dirDestin);
}
}
catch (FileNotFoundException)
{
}
catch (IOException ioex)
{
lbl_UbiDevMensaje.Text = string.Empty;
lbl_UbiDevMensaje.Text = ioex.ToString();
}
}
For the names of the files, I read a gridview, and I add the extensions.
I don't know what is happening,
Please, I hope somebody can help me.
Thanks in advance.
best regards

Solved,
Using server map
private void ExtractosRemover()
{
string dirOrigen = "~/" + "EEQ_" + User.Identity.Name.ToString() + "/";
string dirDestin = "~/" + "FacturasMatch_" + User.Identity.Name.ToString() + "/";
foreach (GridViewRow grd_Row in this.gvwExtractosMatch.Rows)
{
try
{
File.Move( //Mover xml
Server.MapPath(dirOrigen + clean(grd_Row.Cells[7].Text) + ".xml"),
Server.MapPath(dirDestin + clean(grd_Row.Cells[7].Text) + ".xml")
);
File.Move( //Mover pdf
Server.MapPath(dirOrigen + "RIDE_" + clean(grd_Row.Cells[7].Text) + ".pdf"),
Server.MapPath(dirDestin + "RIDE_" + clean(grd_Row.Cells[7].Text) + ".pdf")
);
}
catch (FileNotFoundException)
{ }
}
}

Related

How to append more than two folders to user.home java

guys! I'm trying to append folder to user.home property. It working nice, while I'm using just one additional folder. But when I try to make another two additions (so it looks like user.home+folder1+folder2+folder3) it trows ---
java.lang.IllegalArgumentException: Folder parameter must be a valid folder---
. My though that there is some restriction, but can't find out where.
String fullRoute = null;
File homeDir = new File("MLog");
if (!SiteCo.getEditor().getText().isEmpty() &&
!InciDate.getEditor().getText().isEmpty()) {
homeDir.mkdirs();
fullRoute = System.getProperty("user.home") + File.separator +
//SaveVarTo.getLastVisitedDirectory() +
SaveVarTo.AddPath(SiteCo.getValue().toString()) +
File.separator + SaveVarTo.AddPath(InciDate.getValue().toString());
}
else {homeDir.mkdirs();
// File.separator+homeDir.toString() - without it
fullRoute =
System.getProperty("user.home")+File.separator+homeDir.toString();}
System.out.println(fullRoute);
fileChooser.setInitialDirectory(new File(fullRoute));
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("XML Files", "*.xml"));
//sample of method
public class Variables{
public String AddPath(String name) {
if (!name.isEmpty()) {
//File nou = new File(getLastVisitedDirectory() +"\\" + name);
File nou = new File(name);
if (!nou.exists()) {
nou.mkdirs();
} else {
System.out.println("Folder already exists");
}
}
else{name = null;}
return name;
}}
String fullRoute = null;
File homeDir = new File(System.getProperty("user.home"));
if (SiteCo.getValue() !=null && InciDate.getValue() !=null) {
System.out.println(SaveVarTo.getMainFolder());
fullRoute = homeDir + File.separator + SaveVarTo.getMainFolder() +
File.separator + SiteCo.getValue().toString() +
File.separator + InciDate.getValue().toString();
} else {
fullRoute = homeDir.toString();
}
System.out.println(fullRoute);
File fhd = new File(fullRoute);
if (!fhd.exists())
fhd.mkdirs();
fileChooser.setInitialDirectory(fhd);
fileChooser.getExtensionFilters().addAll(
new FileChooser.ExtensionFilter("XML Files", "*.xml"));

Issue with Bundling and Release mode

When ever i publish my web site with debug="false" mode and BundleTable.EnableOptimizations = true
the server returns the following exception for bundled scripts and styles while requests are just for non authorized requests! But if I run application with debug="true" or user is logged in (via forms authentication in release mode) the exception does not occur and every thins works just fine.
I think there should be a relation between bundling and authentication!! as the exception indicates.
What is wrong?
my bundling codes:
public static void RegisterBundles(BundleCollection bundles)
{
StyleBundle bundleStyles = new StyleBundle("~/bundles/styles/");
bundleStyles.Include(
"~" + Paths.Scripts.AdminSkin.css.reset_css,
"~" + Paths.Scripts.AdminSkin.css.common_css,
"~" + Paths.Scripts.AdminSkin.css.form_css,
//do not move this line to blow
"~" + Paths.Scripts.site.css.standard_css,
"~" + Paths.Scripts.AdminSkin.css.standard_css,
"~" + Paths.Scripts.AdminSkin.css.special_pages_css,
//"~" + Paths.Scripts.AdminSkin.css.simple_lists_css,
//"~" + Paths.Scripts.AdminSkin.css.block_lists_css,
//"~" + Paths.Scripts.AdminSkin.css.planning_css,
//"~" + Paths.Scripts.AdminSkin.css.table_css,
//"~" + Paths.Scripts.AdminSkin.css.calendars_css,
//"~" + Paths.Scripts.AdminSkin.css.wizard_css,
//"~" + Paths.Scripts.AdminSkin.css.gallery_css,
"~" + Paths.Scripts.site.css.login_css,
"~" + Paths.Scripts.site.css.site_css,
"~" + Paths.Scripts.site.css.tables_css,
"~" + Paths.Scripts.site.css.standard_fa_css,
"~" + Paths.Scripts.site.css.theme_selector_css,
"~" + Paths.Scripts.jquery_ui_1_9_2.css.redmond.jquery_ui_1_9_2_custom_css,
"~" + Paths.Scripts.ImageGallery.wt_rotator_css,
"~" + Paths.Scripts.ImageGallery.default_css,
"~" + Paths.Scripts.calendar.aqua.theme_css
);
ScriptBundle bundleScripts = new ScriptBundle("~/bundles/scripts/");
bundleScripts.Include(
//Admin Skin Scripts
"~" + Paths.Scripts.AdminSkin.js.old_browsers_js,
"~" + Paths.Scripts.AdminSkin.js.libs.jquery_hashchange_js,
"~" + Paths.Scripts.AdminSkin.js.jquery_accessibleList_js,
"~" + Paths.Scripts.AdminSkin.js.searchField_js,
"~" + Paths.Scripts.AdminSkin.js.common_js,
"~" + Paths.Scripts.AdminSkin.js.standard_js,
"~" + Paths.Scripts.AdminSkin.js.jquery_tip_js,
"~" + Paths.Scripts.AdminSkin.js.jquery_contextMenu_js,
"~" + Paths.Scripts.AdminSkin.js.jquery_modal_js,
"~" + Paths.Scripts.AdminSkin.js.list_js,
//"~" + Paths.Scripts.AdminSkin.js.libs.jquery_dataTables_min_js,
//jquery plug ins
"~" + Paths.Scripts.jquery_ui_1_9_2.js.jquery_ui_1_9_2_custom_js,
"~" + Paths.Scripts.jquery_cookie.jquery_cookie_js,
"~" + Paths.Scripts.site.js.site_js,
"~" + Paths.Scripts.site.js.clock_js,
"~" + Paths.Scripts.site.js.size_js,
"~" + Paths.Scripts.site.js.cookie_manager_js,
//devexpress related
"~" + Paths.Scripts.site.js.devexpress_theme_js,
"~" + Paths.Scripts.site.js.devexpress_controls_js,
//chart scripts
"~" + Paths.Scripts.Highstock_1_2_5.highstock_src_modified_js,
"~" + Paths.Scripts.Highstock_1_2_5.exporting_js,
"~" + Paths.Scripts.Highstock_1_2_5.highcharts_more_js,
"~" + Paths.Scripts.site.js.chart_fa_js,
//calendar scripts
"~" + Paths.Scripts.calendar.jalali_js,
"~" + Paths.Scripts.calendar.calendar_js,
"~" + Paths.Scripts.calendar.calendar_setup_js,
"~" + Paths.Scripts.calendar.calendar_fa_js,
"~" + Paths.Scripts.calendar.calendar_en_js,
//image gallery scripts
"~" + Paths.Scripts.ImageGallery.js.jquery_wt_rotator_min_js,
"~" + Paths.Scripts.ImageGallery.js.jquery_easing_1_3_min_js,
"~" + Paths.Scripts.ImageGallery.js.preview_js
);
if (RequestCachedItems.Setting.UseGoogleMap)
{
}
else
{
//leaflet map script
bundleScripts.Include("~" + Paths.Scripts.leaflet_0_7.leaflet_src_js);
//leaflet map style
bundleStyles.Include("~" + Paths.Scripts.leaflet_0_7.leaflet_css, new CssRewriteUrlTransform());
}
ScriptBundle bundleLiveScripts = new ScriptBundle("~/bundles/livescripts/");
bundleLiveScripts.Include(
"~" + Paths.Scripts.signalr.jquery_signalR_2_0_0_min_js,
"~" + Paths.Scripts.signalr.hubs_js,
"~" + Paths.Scripts.liveControls.connectionManager_js,
"~" + Paths.Scripts.liveControls.liveControls_js,
"~" + Paths.Scripts.liveControls.liveTables_js
);
bundles.Add(bundleStyles);
bundles.Add(bundleScripts);
bundles.Add(bundleLiveScripts);
BundleTable.EnableOptimizations = true;
}
the exception:
[NullReferenceException: Object reference not set to an instance of an
object.] System.Web.HttpContext.RequestRequiresAuthorization()
+18 System.Web.Caching.OutputCacheModule.OnLeave(Object source, EventArgs eventArgs) +9606196
System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
+136 System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69
I've used Application_PostAuthenticateRequest in Global.ascx.cs
and made HttpContext.Current.User null. I've commented that line and the problem is solved.
public class Global : HttpApplication
{
FormsAuthenticationTicket ticket;
ExtendedUser extendedUser;
protected void Application_PostAuthenticateRequest(Object sender, EventArgs e)
{
//cause of problem
//HttpContext.Current.User = null;
if (FormsAuthentication.CookiesSupported)
{
if (Request.Cookies[FormsAuthentication.FormsCookieName] != null)
{
try
{
ticket = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value);
using (UnitOfWork unit = new UnitOfWork())
{
if (ticket.Name == SecurityHelpers.SuperAdminUserName)
{
SecurityHelpers.GetSuperAdminUser(unit);
}
else
{
extendedUser = SecurityHelpers.GetUser(unit, ticket);
}
}
if (extendedUser != null)
{
string[] roles = extendedUser.Group.GroupRoles.Select(a => a.Role.RoleName).ToArray();
HttpContext.Current.User = new GenericPrincipal(new MyFormsIdentity(extendedUser), roles);
}
}
catch (Exception)
{
// Decrypt method failed.
}
}
}
else
{
// throw new HttpException("Cookieless Forms Authentication is not " +
// "supported for this application.");
}
}
}

How can we return amount in same website by using Paypal Payflow pro account

How can we return deduct amount in same website by using Paypal Payflow pro account?
I am using Paypal Payflow pro account for one of my application. It does transaction but doesn't return deduct amount detail. I am using first time Paypal Payflow account. So if anybody have done such kind of work before kindly share with me.
Hi i have done this, Anybody who needs solution see below:
protected NameValueCollection httpRequestVariables()
{
var post = Request.Form; // $_POST
var get = Request.QueryString; // $_GET
return Merge(post, get);
}
if (!IsPostBack)
{
string output = "";
if (httpRequestVariables()["RESULT"] != null)
{
HttpContext.Current.Session["payflowresponse"] = httpRequestVariables();
output += "<script type=\"text/javascript\">window.top.location.href = \"" + url + "\";</script>";
BodyContentDiv.InnerHtml = output;
return;
}
var payflowresponse = HttpContext.Current.Session["payflowresponse"] as NameValueCollection;
if (payflowresponse != null)
{
HttpContext.Current.Session["payflowresponse"] = null;
bool success = payflowresponse["RESULT"] == "0";
if (success)
{
output += "<span style='font-family:sans-serif;font-weight:bold;'>Transaction approved! Thank you for your order.</span>";
}
else
{
output += "<span style='font-family:sans-serif;'>Transaction failed! Please try again with another payment method.</span>";
}
output += "<p>(server response follows)</p>\n";
output += print_r(payflowresponse);
AdvancedDemoContent.InnerHtml = output;
public string print_r(Object obj)
{
string output = "<pre>\n";
if (obj is NameValueCollection)
{
NameValueCollection nvc = obj as NameValueCollection;
output += "RESULT" + "=" + nvc["RESULT"] + "\n";
output += "PNREF" + "=" + nvc["PNREF"] + "\n";
output += "RESPMSG" + "=" + nvc["RESPMSG"] + "\n";
output += "AUTHCODE" + "=" + nvc["AUTHCODE"] + "\n";
output += "CVV2MATCH" + "=" + nvc["CVV2MATCH"] + "\n";
output += "AMT" + "=" + nvc["AMT"] + "\n";
}
else
{
output += "UNKNOWN TYPE";
}
output += "</pre>";
return output;
}
go to your PayPal merchant account-->profile-->Selling Preferences-->Website Payment Preferences-->Auto Return for Website Payments turn radio button to on,default it should off.after transaction make sure the value are stored in your database.i hope this help you

Executing sqlite statement.executeBatch(), giving fatal error "EXCEPTION_ACCESS_VIOLATION"

I am using sqlite, while using Statement.executeBatch(), the jvm is crashing and giving following fatal error, There is no problem while using PreparedStatement.executeBatch().
I have created separate connection and Statement object from each update in database. The error is...
#
A fatal error has been detected by the Java Runtime Environment:
#
EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d8fde5c, pid=1980, tid=3416
#
JRE version: 6.0_16-b01
Java VM: Java HotSpot(TM) Client VM (14.2-b01 mixed mode, sharing windows-x86 )
Problematic frame:
V [jvm.dll+0xfde5c]
#
If you would like to submit a bug report, please visit:
http://java.sun.com/webapps/bugreport/crash.jsp
#
THE INSERT METHOD IS....
private void runInsert(int records) {
Statement stmt = null;
try {
connection = DriverManager
.getConnection("jdbc:sqlite:jdbcbatch.db");
connection.setAutoCommit(false);
stmt = connection.createStatement();
for (int i = 0; i < records; i++) {
stmt.addBatch("insert into customer values(" + i + ",\"vijith_"
+ i + "\",\"10th floor kaushik nagar serverspace_" + i
+ "\"," + i
+ ",\"11th floor kaushik nagar serverspace_" + i
+ "\")");
// Execute the batch for INSERT
sDate = System.currentTimeMillis();
eDate = 0L;
System.out.println("INSERT started at " + sDate);
int[] recordsInserted = stmt.executeBatch();
eDate = System.currentTimeMillis();
milli = (eDate - sDate);
System.out.println("INSERT ended at " + eDate);
System.out.println("INSERT Time Milliseconds= " + milli
+ " in Seconds= " + milli / 1000);
processTime.put("INSERT", milli);
if (recordsInserted.length != records) {
connection.rollback();
}
connection.commit();
} catch (SQLException e) {
e.printStackTrace();
System.err.println(e.getMessage());
} finally {
try {
if (stmt != null) {
stmt.close();
}
if (connection != null) {
connection.close();
}
} catch (SQLException e) {
System.err.println(e);
}
}
}
can somebody look into my problem, if you find anything helpful please do forward to me.
Thanks in advance.
B. Patel

Proper web redirection with JS window.open call

On a testing server my URL=
http:
//scantdev04:8086/ActivityReport.aspx
I want to prefill a new URL with query data and pass it to the new url:
string sUrl = sRelativePath + "?Organization=" + sOrganization
+ "&&StartDate=" + sStartDate
+ "&&EndDate=" + endDate;
string displayScript = "" +
"window.open('" + sUrl + "', 'DisplayReport', " +
"'width=1200, height=800, toolbar=yes, menubar=yes, resizable=yes, scrollbars=yes')" +
"";
Pretty straight forward.
On dev box, localhost, it is all good.
But in test, the URL spits out like:
http://www.displayreport.aspx/?Organization=Correctional%20Alternatives,%20Inc&&StartDate=09-01-2009&&EndDate=10/6/2009%2012:00:00%20AM
How do I fix the www. that is now there and repeat the "http://scantdev04:8086/"
I would rather not push this to the web.config but will if necessary.
Where does your sRelativePath string come from?
Found this and it seems to work:
old version:
string sRelativePath = Request.ApplicationPath + "/DisplayReport.aspx";
Now changed to :
string sRelativePath = GetWebAppRoot() + "/DisplayReport.aspx";
GetWebRoot() :
string host = (HttpContext.Current.Request.Url.IsDefaultPort) ?
HttpContext.Current.Request.Url.Host : HttpContext.Current.Request.Url.Authority;
host = String.Format("{0}://{1}", HttpContext.Current.Request.Url.Scheme, host);
if (HttpContext.Current.Request.ApplicationPath == "/")
return host;
else
return host + HttpContext.Current.Request.ApplicationPath;

Resources