473,411 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Trying to upload a file gets an error.

UJ
I am trying to write a routine to upload a file through a web service to our
server. I've enclosed the following code and when I run it I get an error:

Exception Occurred. Error: Logon failure: unknown user name or bad
password.\n Trying to write to file I:\\ECS\\Content\\UploadFile.txt Last
Action = File Open

Does this mean that the ASP.Net account (which I haven't changed) doesn't
have rights to the directory or that there is something actually wrong with
the account. Other things work OK - just not this.

The actual code is:
public bool UploadContentFile(string pvsFileName, Byte[] pvobjFile, ref
string prsReturn)
{
bool lbReturnStatus = false;
string lsBaseDirectory =
ConfigurationSettings.AppSettings["ContentDir"].ToString();

FileStream lobjFS = null;

// making sure the base directory string ends with a \ so that
// the file is uploaded to the correct spot
if ( !lsBaseDirectory.EndsWith(@"\") )
lsBaseDirectory += @"\";

string lsFullFileName = lsBaseDirectory + pvsFileName;
string lsLastAction = "";
try
{
// creates the file by opening and setting the fileaccess to write
lsLastAction = "File Open";
lobjFS = File.Open(lsFullFileName, FileMode.Create, FileAccess.Write);

// byte count
long llLen = pvobjFile.Length;

// Write the file
lsLastAction = "File Write";
lobjFS.Write(pvobjFile, 0, Convert.ToInt32(llLen));

// clears the buffer and writes any buffered data
lsLastAction = "File Flush";
lobjFS.Flush();

// close the file so it can be access by other files
lsLastAction = "File Close";
lobjFS.Close();

// return a successful upload status
lbReturnStatus = true;
}
catch ( System.UnauthorizedAccessException exc )
{
// Account does not have enough access to create the file, do to either
login or system permissions
prsReturn = "Unauthorized Access Exception Occurred. Error: " +
exc.Message.ToString();
}
catch ( Exception exc )
{
// catchall error handler
prsReturn = "Exception Occurred. Error: " + exc.Message.ToString() + "
Trying to write to file " + lsFullFileName +
" Last Action = " + lsLastAction;
}
finally
{
// cleanup just in case
if ( lobjFS != null )
{
lobjFS.Close();
}
}
return lbReturnStatus;
}

TIA - Jeff.
Feb 7 '07 #1
0 1303

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: mattrapoport | last post by:
I have a form with an input type='file' element. I click on the Browse button of my file upload element, select a file, and hit open. The file name appears in the textbox portion of the file...
14
by: Al Smith | last post by:
I need help in implementing proper error handling. I am trying to upload a file based on the sample code below. The code works well except if the file selected is too big. I do know about the...
0
by: Benjamin Bittner | last post by:
Hallo NG, ive searched a lot in some google groups, and found many threads, but nothing that helped me. Here is the scenario: I have an aspx page which loads a user control in page.onInit like...
25
by: Neo Geshel | last post by:
This works: <form> <asp:TextBox id="name" /> <%= name.ClientID %> </form> But this DOES NOT work: <form>
9
by: Wayne Smith | last post by:
I've come up against a major headache that I can't seem to find a solution for but I'm sure there must be a workaround and I would really be grateful of any help. I'm currently building a web...
1
by: DavidA | last post by:
I have a very simple form and perl script that is to upload a jpg file. I am not familiar with the perl language but copied the code from a text book. It works fine with all browsers except IE....
6
by: =?ISO-8859-1?Q?J=F8rn?= Dahl-Stamnes | last post by:
I have a strange problem when uploading a PDF document to a web-server. When I try this to a web-server running Apache 2 on a FC 4, it fails. Firefox says that the document contain no data. If I...
5
by: pbd22 | last post by:
Hi. I am trying to poll a long-running process via a hidden IFrame. I am noticing that the online errata gives advice for handling a server response: window.parent.handleServerResponse(); ...
6
by: mlevit | last post by:
I'm trying to upload a file. I use to get the fread(): supplied argument is not a valid stream resource error, but then I placed the code in an if statement with file_exists. The problem is, the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.