c# - the process cannot access the file, it is still being used error -
there lot of answers on question on stackoverflow itself. didn't understand happening.
i tried upload file, file may in count also.
below part of code creating problem-
public actionresult upload(list<httppostedfilebase> file, cardmodel card) { foreach (var item in file) { cardtable cardtable = new cardtable(); if (item != null && item.contentlength > 0) { string extension = path.getextension(item.filename); if (imageextension(extension)) { string path = server.mappath("~/cardphotos/"); item.saveas(path + item.filename); string filename = item.filename;
while saving file item.saveas(path+item.filename);
shows me error "the process cannot access file, being used process.
an alternate solution using sleep
first want understand exception , want know obvious solution.
you can dispose file after saving/creating, this.
item.saveas(path + item.filename); item.dispose();
alternatively, can put save in using block, similar below.
using(var = new httppostedfilebase(item)) { i.save(path + item.filename); }
another reason think of, new upload file trying overwrite existing file, , existing file opened on server.
Comments
Post a Comment