HttpPostedFile file locking issue?

M

M1iS

I have a scenario where a file is posted to page from a desktop application.
Once the upload completes successfully the application calls a web service
and submits other information to a database regarding the file that was
uploaded and then sends out an email that is supposed to have the file that
was just previously uploaded added as an attachment. When I test this on my
development machine with IIS 7 everything works fine. However when I publish
the site and try this on our production server which is running IIS 6 I get
the following error:

Could not find file 'someFilePath'.
Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
at 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)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options, String
msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share)
at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName,
String mediaType)
at System.Net.Mail.Attachment..ctor(String fileName, String mediaType)
at SiteUtility.SendEmailWithAttachment(String toEmail, String subject,
String body, Boolean isHtml, String attachmentFullName, String
attachmentMimeType) in someCodeFile:line 153

In my upload page code behind I save the file to disk using the following:

HttpPostedFile upload = Request.Files[0];
upload.SaveAs(uploadFullName);

Could it be that the HttpPostedFile object is locking up the file? Is there
a better way I could do it by using the HttpPostedFile object’s InputStream
property in a using statement or something along those lines?

Scott
 
M

M1iS

I've double checked the file in the error messages and the files are
definitely in the correct place, not to mention I have the exact same
directory structure on my development machine as I do on the production
machine. I definitely think that the file is getting locked up that's why
I'd like to use a method that implements IDisposable.


Patrice said:
What if you add System.IO.File.Exists to check for the file existence ? From
the message it looks like the exception is that the file is not found, not
that it can't be opened.

Most of the time the issue is developping on a single machine while having
multiple machines in production and not realizing it could make a difference
about how file are located.

For now I would add an existance check to make sure the file is really there
(and display the name to see if this is what you expect)... Else a file that
is used by IIS is locked for a shrt period but IMO this is not your case...

--
Patrice


M1iS said:
I have a scenario where a file is posted to page from a desktop
application.
Once the upload completes successfully the application calls a web service
and submits other information to a database regarding the file that was
uploaded and then sends out an email that is supposed to have the file
that
was just previously uploaded added as an attachment. When I test this on
my
development machine with IIS 7 everything works fine. However when I
publish
the site and try this on our production server which is running IIS 6 I
get
the following error:

Could not find file 'someFilePath'.
Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String
maybeFullPath)
at 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)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share, Int32 bufferSize, FileOptions options, String
msgPath, Boolean bFromProxy)
at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess
access, FileShare share)
at System.Net.Mail.AttachmentBase.SetContentFromFile(String fileName,
String mediaType)
at System.Net.Mail.Attachment..ctor(String fileName, String mediaType)
at SiteUtility.SendEmailWithAttachment(String toEmail, String subject,
String body, Boolean isHtml, String attachmentFullName, String
attachmentMimeType) in someCodeFile:line 153

In my upload page code behind I save the file to disk using the following:

HttpPostedFile upload = Request.Files[0];
upload.SaveAs(uploadFullName);

Could it be that the HttpPostedFile object is locking up the file? Is
there
a better way I could do it by using the HttpPostedFile object's
InputStream
property in a using statement or something along those lines?

Scott
 
M

M1iS

Okay I tried the File.Exists method and it says the file is not there. I
check the location of where it says it can't supposedly find the file and the
file is clearly there. I also turned off the virus scanning software on the
server and still no luck.
 
M

M1iS

Boy don't I feel stupid. Turns out that my desktop application that was
uploading the file and calling the web service still had a reference to the
local version of my site on my development machine. So when the soap call
was made of course it couldn't find the file, it's on a server 3000 miles
away!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top